Phonegap plugin result when app is not active anymore

那年仲夏 提交于 2019-12-11 01:30:16

问题


I'm trying to edit the phonegap/cordova PushPlugin plugin for android in order to not create an status-bar Notification when app is not active but always doing some javascript work.

I want to receive my GCM message an do some work on it with javascript at anytime.

GCM message received by PushPlugin => javascript function called.

I've no problem to make this working when my cordova app is active (ie in foreground or paused). But I can't use sendJavascript(...) when the app has been destroyed. It makes the app crash.

Is there a way to keep the callback context or to wake the webview when the app is not active anymore ?

PS : I'm completely lost within all my google research that give me old results and all different versions of phonegap.

UPDATE :

I've actually that code :

public class PushPlugin extends CordovaPlugin {

private static CallbackContext callbackCont;


public boolean execute(String action, JSONArray data, CallbackContext callbackContext) {
       callbackCont = callbackContext;

       PluginResult progressResult = new PluginResult(PluginResult.Status.OK, "Start");
       progressResult.setKeepCallback(true);
       callbackCont.sendPluginResult(progressResult);
}


//Fired by an Receiver
public static void action(JSONObject _json) {

        PluginResult progressResult = new     PluginResult(PluginResult.Status.OK, "Message");
        progressResult.setKeepCallback(true);
        callbackCont.sendPluginResult(progressResult);
}

}

As expected the javascript success function is fired only when app is active (foreground or paused)


回答1:


Since the app is at first a chrome packaged app, build for mobile with cca, I use now the chrome app GCM plugin that is just supported by cca and that wake up the app when an new message is coming.

See https://github.com/MobileChromeApps/mobile-chrome-apps/tree/master/chrome-cordova/plugins/chrome.gcm



来源:https://stackoverflow.com/questions/23349847/phonegap-plugin-result-when-app-is-not-active-anymore

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!