android - GCM notification executes only once -
i receiving notifications gcm server android app.
when select notification first time, notification launches target activity. however, following notifications don't launch activity.
the following gcmintentservice class:
public class gcmintentservice extends gcmbaseintentservice{ private string tag = "rt-gcm"; @override protected void onerror(context arg0, string arg1) { // todo auto-generated method stub log.e(tag, "gcm-service: error"); } @override protected void onmessage(context context, intent intent) { // todo auto-generated method stub int nid = integer.parseint(intent.getstringextra("nid")); try { // generatenotification(context, nid, intent.getstringextra("message")); generatenotification(context, intent); } catch (exception e) { // todo auto-generated catch block e.printstacktrace(); } } @override protected void onregistered(context context, string arg1) { // todo auto-generated method stub log.e(tag, "gcm-service: registered"); accountmanager accountmanager = accountmanager.get(context); accountmanager.getaccounts(); account account = getaccount(accountmanager); new gcmservercall().register(arg1, "tony", account.name); } @override protected void onunregistered(context arg0, string regid) { // todo auto-generated method stub log.e(tag, "gcm-service: un-registered"); new gcmservercall().unregister(regid); } /** * issues notification inform user server has sent message. * * copied code fragment gcm.zip example file downloaded http://cl.ly/0c151616032t */ private static void generatenotification(context context, intent myintent) { integer nid = integer.parseint(myintent.getstringextra("nid")); int icon = r.drawable.ic_launcher; long when = system.currenttimemillis(); notificationmanager notificationmanager = (notificationmanager) context.getsystemservice(context.notification_service); notification notification = new notification(icon, myintent.getstringextra("message") + "["+nid+"]", when); string title = context.getstring(r.string.app_name); intent notificationintent = new intent(context, articlereader.class); log.e("testing ...", "sending nid#" + nid); notificationintent.putextra("nid", nid); notificationintent.putextra("nid", nid); notificationintent.putextra("test", "working"); // set intent not start new activity notificationintent.setflags(intent.flag_activity_clear_top | intent.flag_activity_single_top); pendingintent intent = pendingintent.getactivity(context, 0, notificationintent, 0); notification.setlatesteventinfo(context, title, myintent.getstringextra("message") + "["+nid+"]", intent); notification.flags |= notification.flag_auto_cancel; notification.flags |= notification.flag_show_lights; notification.defaults = notification.default_all; notificationmanager.notify(0, notification); } /**** * retrieving google account(s) registered on target device * @param accountmanager * @return */ private account getaccount(accountmanager accountmanager){ account[] accounts = accountmanager.getaccountsbytype("com.google"); log.i(tag, "we have " + accounts.length + " accounts!"); return accounts[0]; } } update:
i have discovered thing new. after first , successful launching of articlereader.class selecting notification, selecting following notifications work if navigate app away articlereader. in otherwords, if instance of articlereader active view, notifications attempts launch same activity won't work.
can tell me how launch activityreader class repeatedly via notifications if activityreader activity current view, please?
from docs
public void notify (int id, notification notification)
post notification shown in status bar. id - identifier notification unique within application.
instead of 0 should generate unique id different notification on status bar, use time zone unique identifier
Comments
Post a Comment