user2379198
user2379198

Reputation: 3

Sending messages with pushwoosh+phonegap results in a "null" message

I am relatively new to developing android apps. I am using pushwoosh with phonegap to try and receive push notifications. I followed the setups for both as directed. The problem I am facing now is that when I send a message from my pushwoosh account, the alert that pops does not show the message but in fact shows "null".

Here is a look at the console messages I get:

05-13 20:08:26.568: D/dalvikvm(914): GC_CONCURRENT freed 273K, 21% free 3296K/4144K, paused 5ms+2ms, total 56ms
05-13 20:08:26.568: D/dalvikvm(914): WAIT_FOR_CONCURRENT_GC blocked 32ms
05-13 20:08:26.739: I/Choreographer(914): Skipped 37 frames!  The application may be doing too much work on its main thread.
05-13 20:16:36.978: V/GCMBroadcastReceiver(914): onReceive: com.google.android.c2dm.intent.RECEIVE
05-13 20:16:36.978: V/GCMBroadcastReceiver(914): GCM IntentService class: com.arellomobile.android.push.PushGCMIntentService
05-13 20:16:36.978: V/GCMBaseIntentService(914): Acquiring wakelock
05-13 20:16:37.117: I/GCMIntentService(914): Received message
05-13 20:16:37.188: V/GCMBaseIntentService(914): Releasing wakelock
05-13 20:16:37.308: E/doOnMessageReceive(914): message is: {"message":"Hello","foregroud":true,"from":"41772830302","collapse_key":"do_not_collapse","onStart":false}
05-13 20:16:37.379: D/CordovaLog(914): user data: undefined
05-13 20:16:37.379: W/Web Console(914): user data: undefined at file:///android_asset/www/PushNotification.js:147
05-13 20:16:37.579: D/dalvikvm(914): GC_CONCURRENT freed 290K, 19% free 3395K/4144K, paused 5ms+3ms, total 106ms

You can see that the console shows the original message "Hello".

Here is a look at my PushNotification.js:

function initPushwoosh()
{
    var pushNotification = window.plugins.pushNotification;
    pushNotification.onDeviceReady();

    pushNotification.registerDevice({ projectid: "PROJECT_ID", appid : "APP_ID" },
        function(status) {
            var pushToken = status;
            console.warn('push token: ' + pushToken);
        },
        function(status) {
            console.warn(JSON.stringify(['failed to register ', status]));
        }
    );

    document.addEventListener('push-notification', function(event) {
        var title = event.notification.title;
        var userData = event.notification.userdata;

        console.warn('user data: ' + JSON.stringify(userData));
        navigator.notification.alert(title);
    });
}

function init() {
document.addEventListener("deviceready", initPushwoosh, true);
}

For some reason, my user data is undefined. What could be causing this issue?

Thanks.

Upvotes: 0

Views: 2490

Answers (1)

Gareth Nel
Gareth Nel

Reputation: 217

That's because you are not using the message value that is received from the JSON response. Try this.

document.addEventListener('push-notification', function(event) {
    var title = event.notification.title;
    var userData = event.notification.userdata;
    var msg = event.notification.message;

    console.warn('user data: ' + JSON.stringify(userData));
    navigator.notification.alert(msg);
});

Upvotes: 2

Related Questions