How can i access the content message from notifications and redirect to different pages?
I've created a javacript alert at push notification in the main page of my app and it shows me the alert when i receive notifications, but i also tried to create javascript code to manage notifications at device ready event and after that i can't see the notification alert from the javasctipt push notification event
I paste the code from https://github.com/phonegap-build/Pus... and edit to show me alerts:
alert("custom device ready event");
var pushNotification;
pushNotification = window.plugins.pushNotification;
if ( device.platform == 'android' || device.platform == 'Android'){
pushNotification.register(
successHandler,
errorHandler,
{
"senderID":"senderID",
"ecb":"onNotification"
});
}
// result contains any message sent from the plugin call
function successHandler (result) {
alert('result = ' + result);
}
// result contains any error description text returned from the plugin call
function errorHandler (error) {
alert('error = ' + error);
}
//ecb (Amazon Fire OS, Android and iOS)
//Event callback that gets called when your device receives a notification
// Android and Amazon Fire OS
function onNotification(e) {
//$("#app-status-ul").append('EVENT - RECEIVED:' + e.event + '');
Code: Select all
switch( e.event ) {
case 'registered':
if ( e.regid.length 0 ){
alert('REGISTERED - REGID:' + e.regid);
}
break;
case 'message':
// if this flag is set, this notification happened while we were in the foreground.
// you might want to play a sound to get the user's attention, throw up a dialog, etc.
if ( e.foreground )
{
alert('--INLINE NOTIFICATION--');
// on Android soundname is outside the payload.
// On Amazon FireOS all custom attributes are contained within payload
var soundfile = e.soundname || e.payload.sound;
// if the notification contains a soundname, play it.
var my_media = new Media("/android_asset/www/"+ soundfile);
my_media.play();
}
else
{ // otherwise we were launched because the user touched a notification in the notification tray.
if ( e.coldstart )
{
alert('--COLDSTART NOTIFICATION--');
}
else
{
alert('--BACKGROUND NOTIFICATION--');
}
} // else
break; //case message
case 'error':
alert('ERROR - MSG:' + e.msg);
break;
default:
alert('EVENT Unknown: an event was received and we do not know what it is');
break;
} // switch (e.event)
} // function errorHandler
Thank you very much.