Start a new topic

Push payload on Phonegap Android not working

The Phonegap push plugin, com.phonegap.plugins.PushPlugin is not receiving the message payload it expects. On iOS it's fine, but on Android, the message to the notification system (when the app is in the background) is "" . Might very well be a problem with the plug-in itself, but just wanted to check with you to see how you are broadcasting the payload.

The plug-in is expecting the message to come in via "message" node, according to the docs.

To confirm - yes, msg is the entire payload.
My issue is also on the push notification tray side, where I cannot get it to pull a specific part of the payload instead of showing the entire contents.

I'm using the plugin install: phonegap local plugin add ""

In the GCMIntentService handler createNotification, I've tried messing around with some of the code there, but cannot get it to pull specific parts of the message.

In the line:

String message = extras.getString("msg");

It seems that "msg" is the entire payload.
Hey Randolph,

Which plug-in are you using? My problem is primarily the notification tray. For me it comes up as . Now that I know that send and sendPayload format the message differently, the in-App side is fine because I can code for it. So now I need to start looking into the java side of things and figure out how it expects the formatting and modify it.
Are you also experiencing an issue with how the notification comes up in the Android notification tray? For me the notification displays the entire object (e.g., "{message: txt, msg: txt, from: "Hiyu", subject:txt }"

I can figure out how to have the client-side javascript get the object properties, but I can't figure out how to get the plug-in to pull out the right properties from the object when displaying in the notification tray in Android.

Am i missing something?
Yes, that is the expected format.
Hey Mark,

Here's the difference in payload received:

With modules.push.send:

V/PushPlugin(16069): extrasToJSON: {"payload":{"msg":"Daniel Roizman commented on your post: Several variants on packaging, choose wisely"},"collapse_key":"do_not_collapse","from":"1063735744857","foreground":true,"event":"message"}

and with modules.push.sendPayload:

V/PushPlugin(16069): extrasToJSON: {"payload":{"msg":{"message":"Daniel Roizman has just commented on your post: So good. Not too sweet."}},"collapse_key":"do_not_collapse","from":"1063735744857","foreground":true,"event":"message"}

with sendPayload, the extra payload is stuffed into a dictionary in payload.msg so my client side javascript needs to access payload.msg.message .

Is that expected for the two to send commands to send differently? If so, I can account for that on my end.

I’m not sure what is going on. In the Android Emulator, using `modules.push.send()` works fine - the app alerts the push message both in back- and foreground.

When using `modules.push.sendPayload()`, the app alerts the push payload (which will alert `[object Object]`). Meaning that, in your app, the `data.message` contains the payload (which is an object) sent.

Are you trying this out on the emulator or real device? Either way, when you get the "missing message content", is there something logged in LogCat?
Not sure what's up exactly.

var txt = "testing comment";

var iOSAps = { alert: txt };

var iOSExtras = {from: "Hiyu", subject: txt};

var androidPayload = {message: txt, msg: txt, from: "Hiyu", subject:txt }

modules.push.sendPayload(docs, iOSAps, iOSExtras, androidPayload);

On iOS with the app in the background, the notification appears properly in iOS Notification Centre.

On Android, with the app in the background, the notification appears but the body of it says .

When the app is in the foreground,

iOS also works fine but Android receives an object instead of a string [object Object] for payload.msg.

Interestingly, if use modules.push.send instead of sendPayload, iOS is fine, Android background has the same error but Android foreground works correctly and payload.msg is a string, not an object.

I don't expect you to debug on the client side, but there seems to be some inconsistency on send and sendPayload. Can you document a snapshot of both? I can then compare it against the push plug-in for phonegap and see what's going wrong.
I am able to successfully receive a push notification in Android using the broadcast function. How are you sending your push notifications?

The plugin reads the "msg" property, since that is what is set when you send push notifications through Kinvey (either using collection hooks or custom endpoints).
Hi Daniel,

I just saw that this was under Android so I'm updating to JavaScript since it's the PhoneGap SDK-- that will help get eyes on it faster!
Login or Signup to post a comment