[英]show push notification only when app is not running in cordova android
[英]Push notification not showing when app is in running in cordova
我已經在cordova中使用( https://github.com/phonegap-build/PushPlugin )成功實現了推送通知。一切正常工作,除了在應用程序運行時不顯示推送通知(即前台)。
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 )
{
// if this flag is set, this notification happened while we were in the foreground.
//this is not working
if(e.foreground){
var myMedia = new Media("/assets/www/img/beep.mp3");
my_media.play();
}else{
// otherwise we were launched because the user touched a notification in the notification tray.
}
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) {
//when you are running the app, you get the alert
alert(e.payload.message);
}
else {
//do something for the case where user is not using the app.
if (e.coldstart)
console.log('--COLDSTART NOTIFICATION--' + '');
else
console.log('--BACKGROUND NOTIFICATION--' + '');
$window.location.href = ('#/bucket/notification');
}
break;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.