如何在后台运行android phonegap应用程序(关闭应用程序后)?

我使用了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文档,您无法在后台运行应用程序,js无法继续运行。 通知能够工作的原因是因为他们使用本机系统发送通知。

为了使进程在后台运行,您需要创建一个使用本机操作系统的插件。

我使用PhoneGap创建了一个Android应用程序,当我按下主页按钮时,我的应用程序保持在后台(我的上次测试时间超过1小时)。 但是当我启动其他App时,Android操作系统会杀死我的应用程序。

要启用此行为,您需要添加android权限:

到你的清单

你还需要添加:

到文件夹res/xml config.xml

我希望这篇文章可以帮到你:)