Start a new topic

push.sendPayLoad displays JSON data as message text in push notification

The business logic guide for PhoneGap indicates one can use the following code from a Custom Endpoint:

push.sendPayload(user, iOSAps, iOSExtras, androidPayload);

I am able to send out push messages successfully, but when when the push message appears on my Android device, it displays the entire JSON object send as the androidPayload parameter.

In other words, the notification reads:

{message: "Message would go here", from: "My app", subject: "A subject line" }

Instead of just the message. Any suggestions on what I'm doing wrong? Or missing? Are there Urban Airship features that are not in the documentation that enables Payload processing?

var iOSAps = { alert: "You have a new message", badge: 2, sound: "notification.wav" };

var iOSExtras = {from: "Kinvey", subject: "Welcome to Business Logic", msgtype: "dailycheckin"};

var androidPayload = {message: "Message would go here", from: "My app", subject: "A subject line" };

var push = modules.push;

push.sendPayload(user, iOSAps, iOSExtras, androidPayload);

Depends on how you handle receiving push notifications in your app. What does the client-side code look like? Did you take a look at the [PhoneGap docs]( on handling received push notifications?
The client-side code matches the PhoneGap documentation. I have currently setup the two handlers to parse out the JSON object I'm sending via push.sendPayLoad, which is working just fine.

notificationCallbackGCM: function(e)

onNotificationAPN: function(e)

But, my issue is not the app handling the JSON object (which works just fine), but how to get the push notification that appears on the phone when the app is in the background or not running, which displays the entire JSON object instead of just the message.

Seems like I'm sending push.sendPayLoad, but the notification pushes out (when app is not in foreground) like this:

{message: "Message would go here", from: "My app", subject: "A subject line" }

Instead of just the message, "Message would go here."

Maybe I'm missing something? I checked the PhoneGap docs again and even tried looking at the Urban Airship docs to see if there were any clues on how the androidPayload needs to be structured so that notifications can be set to have a title, icon, etc...
Android push does not use Urban Airship, but rather uses Google Cloud Messaging. The payload sent is the raw JSON. It is up to your code to parse the JSON data received in the callback.

I am having the same issue.

var androidPayload = {title:"Friend Request",message:"You have a new friend request!"};

push.sendPayload(user, iOSAps, iOSExtras, androidPayload, function(err,result){

using the above, title gets displayed properly, but message comes up in the notification as the entire Json object.

What are the androidPayload data object names meant to be to be displayed properly on the app ? 

The example has message,from and subject . Changing subject to title I was able to get the title to work, however message still displays wrong.

I fixed this problem by changing to this plugin

Login or Signup to post a comment