android - GCM notification received but not displaying -
my android app , server have been configured receive , send push notifications. app receives notification , shows in logcat whether app open, in background or not running should. however, i'm having problem getting display. no matter do, can't show in notification center or come in alert vibrates phone or makes sound.
what missing? i'm using gcm plugin here: https://github.com/marknutter/gcm-cordova
i've tried getting send notification using notificationcompat, i've been unsuccessful.
-->json gcm passed function...
@override protected void onmessage(context context, intent intent) { log.d(tag, "onmessage - context: " + context); // extract payload message bundle extras = intent.getextras(); if (extras != null) { try { log.v(me + ":onmessage extras ", extras.getstring("message")); jsonobject json; json = new jsonobject().put("event", "message"); // application on host server sends "extras" variables message , msgcnt // depending on how build server app can specify variables want send json.put("message", extras.getstring("message")); json.put("msgcnt", extras.getstring("msgcnt")); log.v(me + ":onmessage ", json.tostring()); gcmplugin.sendjavascript( json ); notificationcompat.builder mbuilder = new notificationcompat.builder(this) .setsmallicon(r.drawable.notification_icon) .setcontenttitle("test") .setcontenttext("test"); // send message javascript application } catch( jsonexception e) { log.e(me + ":onmessage", "json exception"); } } }
you're pretty close, you're missing single step. code prepares notification doesn't show it. put these lines after notificationcompat.builder
code:
final int notificationid = 1; notificationmanager nm = (notificationmanager) getapplicationcontext() .getsystemservice(context.notification_service); nm.notify(notificationid, mbuilder.build());
the notification id arbitrary number can use retrieve notification if need update or remove later.
Comments
Post a Comment