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

Mer*_*rcy 7 javascript jquery cordova

我使用了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); 
    }
Run Code Online (Sandbox Code Playgroud)

我在前台和后台都获得了通知图标.但是,当在应用程序中单击按钮并持续调用我的wcf服务时,可以运行整个应用程序在后台运行.即使在运行时我也需要获取警报在后台如何做到这一点?

navigator.systemNotification.onBackground():此行在后台运行应用程序,或者不是其他方式,仅用于在关闭应用程序后显示通知.

请指导我,提前谢谢.

Dre*_*man 1

根据phonegap文档,您无法在后台运行应用程序,js无法继续运行。通知之所以能够工作,是因为它们使用本机系统来发送通知。

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