Closed miqmago closed 7 years ago
There are 2 types of payloads you can receive with GCM on Android:
1) "data" payload (not visible to the user by default) 2) "notification" payload (visible as a system notification, may contain title, message, etc)
The JSON object you supply via "data" is accessible to the Intent extras of your push BroadcastReceiver directly (i.e. intent.getStringExtra("id")
for sending data = {id: 1}
).
The notification
object, on the other hand, is accessible via intent.getStringExtra("gcm.notification.x")
as you discovered.
It all depends on which one you actually want to send and interact with.
Thanks! Is this something related to google or to this plugin? I'm interested on this in order to know if I have to give backwards compatibility to the cordova plugin or I can definetely modify it.
@miqmago It is the way GCM works. The way GCM passes both of these payloads to your BroadcastReceiver is by prefixing the notification
keys with gcm.notification.
Thanks!
This is quite strange: in android I'm receivig extras as:
I've placed a
console.log('node-gcm', message);
just before https://github.com/ToothlessGear/node-gcm/blob/master/lib/sender.js#L16 and the console is like this:So it seems good to me. I'm mainaining the
cordova-push-notifications
plugin and it relies onextras.getString("message")
to handle notifications while app is in background (see https://github.com/appfeel/cordova-push-notifications/blob/master/src/android/com/plugin/gcm/GCMIntentService.java#L75).If this is the new specification I could modify the plugin, but I'm not sure if this is new standard, or if something should be changed in calling code (I'm also maintaining https://github.com/appfeel/node-pushnotifications and it depends on this plugin for android, so it should be changed there as well), or if this is an issue of this plugin or if that depends on google.