我已经在 github( https://github.com/saileshmittal/phonegap-system-notification-plugin ) 中为 android phonegap 使用了系统通知插件。我已经在我的 index.html 中使用了这段代码
我的代码是:
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
var not_title = 'Message';
var not_text = 'Zou dit werken?';
var not_tText = 'Message';
navigator.systemNotification.onBackground();
navigator.systemNotification.onForeground();
navigator.systemNotification.createStatusBarNotification(not_title, not_text, not_tText);
}
我在前台和后台都得到了通知图标。但是当在应用程序中单击按钮并连续调用我的wcf 服务时,是否可以运行整个应用程序以在后台运行。此外,即使在后台运行时我也需要收到警报。如何做到这一点?
navigator.systemNotification.onBackground()
:此行在后台运行应用程序或仅在关闭应用程序后显示通知。
请指导我,在此先感谢。
最佳答案
我用 PhoneGap 制作了一个 Android 应用程序,当我按下主页按钮时,我的应用程序停留在后台(在我上次测试中它停留了 1 个多小时)。但是当我启动其他应用程序时,Android 操作系统会终止我的应用程序。
要启用此行为,您需要添加 android 权限:
<uses-permission android:name="android.permission.WAKE_LOCK" />
到你的 list
你还需要添加:
<preference name="exit-on-suspend" value="false" />
给你的config.xml
在文件夹中 res/xml
希望这篇文章能帮到你:)
关于javascript - 如何在后台运行 android phonegap 应用程序(关闭应用程序后)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9377064/