android - Sending messages with pushwoosh+phonegap results in a "null" message -
i relatively new developing android apps. using pushwoosh phonegap try , receive push notifications. followed setups both directed. problem facing when send message pushwoosh account, alert pops not show message in fact shows "null".
here @ console messages 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! application may doing work on 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 @ 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 console shows original message "hello".
here @ 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 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 reason, user data undefined. causing issue?
thanks.
that's because not using message value received 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); });
Comments
Post a Comment