Hi there,

I have this code which is running good on IOS but on android i am getting push but getting only header message is not getting displayed in android.

// Change this to the 'Application Code' of your Pushwoosh.com Application var PUSHWOOSH_APPID = "PushID here";

// For Android, we need the 'Project Number' you created at https://console.developers.google.com // While you're there, make sure that 'Google Cloud Messaging for Android' is enabled (menu item API's) var GOOGLE_PROJECT_ID = "Project number here";

(function (global) { app = global.app = global.app || {};

document.addEventListener('deviceready', function () {
    initPushwoosh();
    //window.plugins.pushNotification.unregisterDevice(onSuccess, onError);
}, false);

})(window);

// Pushwoosh code: // TODO de-duplicate; iOS and Android are very similar)

function initPushwooshWP8() { var pushNotification = window.plugins.pushNotification;

// Set push notification callback before we initialize the plugin. This is called when a push is received.
document.addEventListener('push-notification', function (event) {
    navigator.notification.alert(JSON.stringify(event), null, 'Push received', 'Close');
});

//initialize the plugin
pushNotification.onDeviceReady({ appid: PUSHWOOSH_APPID });

}

function initPushwooshIOS() { var pushNotification = window.plugins.pushNotification; // Set push notification callback before we initialize the plugin. This is called when a push is received. document.addEventListener('push-notification', function (event) { var notification = event.notification; navigator.notification.alert(notification.aps.alert);

    //to view full push payload
    navigator.notification.alert(JSON.stringify(notification));

    //reset badges on icon
    pushNotification.setApplicationIconBadgeNumber(0);
});

//initialize the plugin
pushNotification.onDeviceReady({ pw_appid: PUSHWOOSH_APPID });
Deviceregister();

// reset (hide) badges on start by setting it to 0
pushNotification.setApplicationIconBadgeNumber(0);

}

Deviceregister = function () { var pushNotification = window.plugins.pushNotification; //alert(pushNotification.registerDevice); pushNotification.registerDevice( function (success) { // not all platforms agree on the result type var token = typeof result === 'string' ? result : result['deviceToken']; alert("success" + token); }, function (fail) { navigator.notification.alert(JSON.stringify(['failed to register ', status])); }); }; function initPushwooshAndroid() {

var pushNotification = window.plugins.pushNotification;
// Set push notification callback before we initialize the plugin. This is called when a push is received.
document.addEventListener('push-notification', function (event) {
    var title = event.notification.title;
    var userData = event.notification.userdata;
    var msg = event.notification.message;

    if (typeof (userData) != "undefined")
    {
        alert('user data: ' + JSON.stringify(userData));
    }

        alert(msg);
});

// This will trigger all pending push notifications on start.
pushNotification.onDeviceReady({ projectid: GOOGLE_PROJECT_ID, appid: PUSHWOOSH_APPID });
Deviceregister();

}

function initPushwoosh() { //if (window.navigator.simulator === true) { // alert('This plugin is not available in the simulator.'); // return; //} else if (window.plugins.pushNotification === undefined || typeof window.plugins.pushNotification.onDeviceReady == "undefined") { // alert('Plugin not found1 for push. Maybe you are running in AppBuilder Companion app which currently does not support this plugin.'); // return; //}

switch (device.platform) {
    case "Android":
        initPushwooshAndroid();
        break;
    case "iPhone":
    case "iOS":
        initPushwooshIOS();
        break;
    case "Win32NT":
        initPushwooshWP8();
        break;
    //default:
    //    alert('Unsupported push platform: ' + device.platform);
}

}

second question is how I can get registered device token in android?

Thanks,

Vivek.

asked 11 Sep '14, 07:29
vivekkumar96's gravatar image

vivekkumar96
112

Hi,

Could you please let me know why?

Thanks,

Vivek.

permanent link
answered 11 Sep '14, 20:52
vivekkumar96's gravatar image

vivekkumar96
112

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×447
×446
×326

question asked: 11 Sep '14, 07:29

question was seen: 2,017 times

last updated: 11 Sep '14, 20:52