gpt4 book ai didi

android - 当应用程序处于前台时,Cordova PushPlugin 不工作

转载 作者:行者123 更新时间:2023-11-29 20:33:48 26 4
gpt4 key购买 nike

我正在使用 Cordova 3.5.0-0.2.6 来创建 Android 应用程序并使用 PushPlugin 2.2.1 来推送通知。

一切正常,当应用程序在后台时,我的机器人通知栏中会收到通知,但当它在前台时,收到通知时什么也没有发生。想让它播放声音,甚至显示弹出警报,让用户知道他有新通知。从插件的 github 页面 ( 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)
{
// 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.
// playing a sound also requires the org.apache.cordova.media plugin
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.
window.location = 'iframe.html?url=' + e.payload.url;
if (e.coldstart) {
//$("#app-status-ul").append('<li>--COLDSTART NOTIFICATION--' + '</li>');
} else{
//$("#app-status-ul").append('<li>--BACKGROUND NOTIFICATION--' + '</li>');
}
}

不确定应该将 beep.wav 文件放在哪里,我把它放在了 www 文件夹中,但我 100% 确定那是放它的地方。

有人遇到过这个问题吗?知道我在这里可能遗漏了什么吗?

谢谢,

卢西亚诺

最佳答案

对于 android 请添加属性 "forceShow": "true" 它应该可以工作..

示例代码如下:

var push = PushNotification.init({
"android": {
"senderID": "xxxxxxxxx",
"forceShow": "true",
"icon": "icon",
"sound": true,
"vibration": true,
"badge": true
},
"browser": {
},
"ios": {
"senderID": "xxxxxxxxx",
"icon": "icon",
"gcmSandbox": true,
"sound": true,
"vibration": true,
"badge": true
},
"windows": {}
});

关于android - 当应用程序处于前台时,Cordova PushPlugin 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31619507/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com