Quantcast
Viewing all articles
Browse latest Browse all 8068

Android Push Notifications Flags

Hi there, I'm wondering if someone could help me with setting correct flags when receiving android push notifications through GCM.

I'm currently trying to properly handle the situation when the push notification is received and the application is running in the background. In this case I wish:

a) the user be able to tap on the notification icon to bring the application to the foreground. I would like to avoid relaunching the application completely (i.e. showing the splash screen at the beginning), if possible.

b) OR, preferably, automatically launch the application without waiting for the user to tap over the notification, as soon as the push is received. I'm not sure if it is possible at all, but this would be the best solution in my case.

With my current code, when the user taps on the Notification, nothing happens. They have to go to the recent apps to launch the application:

// create an intent and a pending intent in order to open the app when the users clicks on the notification
var notificationIntent = Ti.Android.createIntent({
    className: config.applicationActivity,
    packageName: config.applicationId
});
 
// Create a PendingIntent to tie together the Activity and Intent
var intent = Ti.Android.createPendingIntent({
    action : Ti.Android.ACTION_MAIN,
    flags : Ti.Android.FLAG_ACTIVITY_NEW_TASK | Ti.Android.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Titanium.Android.FLAG_UPDATE_CURRENT,
    intent: notificationIntent
});
 
// check http://docs.appcelerator.com/titanium/2.1/index.html#!/api/Titanium.Android.Notification
var notification = Ti.Android.createNotification({
    contentIntent: intent,
    contentTitle: tickerText,
    contentText: tickerText,
    tickerText: tickerText,
    icon: Ti.App.Android.R.drawable.appicon,
    flags : Titanium.Android.ACTION_VIEW | Titanium.Android.FLAG_AUTO_CANCEL | Titanium.Android.FLAG_SHOW_LIGHTS,
    defaults: Titanium.Android.DEFAULT_LIGHTS | Titanium.Android.DEFAULT_VIBRATE
});
 
//trying to use custom sound alert
var sound = config.getOrCopyAudioFile();
if (sound){
    notification.sound = sound; 
}
else {
    notification.defaults = Titanium.Android.DEFAULT_ALL;
}
 
Ti.Android.NotificationManager.notify((new Date().getTime()), notification);
I think I have a complete mess with Intent and Notification flags, but I could't manage to set them in a way to achieve my goals. I'm wondering if someone could help me out.

Thanks so much!


Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>