简体   繁体   English

获取cordova插件中的上下文

[英]Get context in cordova plugin

Hi I'm using this GCM notification plugin for android and works almost perfect, the only issue I have is when the user force close my app or when the device is shutted down the notification service stops working. 嗨,我正在使用这个 GCM通知插件的Android和工作几乎完美,我唯一的问题是当用户强制关闭我的应用程序或当设备关闭时,通知服务停止工作。

I've looked the plugin code problem and realized that the following function causes the problem. 我查看了插件代码问题并意识到以下函数会导致问题。

     public static void sendJavascript( JSONObject _json )
      {
        String _d =  "javascript:"+gECB+"(" + _json.toString() + ")";
            Log.v(ME + ":sendJavascript", _d);

            if (gECB != null ) {
              gwebView.sendJavascript( _d );
            }
}

When the device is shutted down and then turned on or the application is force closed, gwebView reference is lost. 当设备关闭然后打开或应用程序强制关闭时,gwebView参考将丢失。 If I try to use the method gwebView.sendJavascript( _d ) I get a null pointer exception. 如果我尝试使用方法gwebView.sendJavascript(_d)我得到一个空指针异常。

Reviewing the plugin code I noticed that gwebView is referenced when registering the device just as this code shows: 回顾一下插件代码,我注意到在注册设备时引用了gwebView,就像这段代码所示:

public static Plugin gwebView;
  private static String gECB;
  private static String gSenderID;

  @SuppressWarnings("deprecation")
@Override
  public PluginResult execute(String action, JSONArray data, String callbackId)
  {

    PluginResult result = null;

    Log.v(ME + ":execute", "action=" + action);

    if (REGISTER.equals(action)) {

      Log.v(ME + ":execute", "data=" + data.toString());

      try {

        JSONObject jo= new JSONObject(data.toString().substring(1, data.toString().length()-1));

        gwebView = this;

..............................More code here......................

The notifications are received on background but I can't invoke any javascript methods since gwebView points nothing. 通知是在后台收到的,但我无法调用任何javascript方法,因为gwebView没有任何指示。

My approach is to show a generic notification on statusbar whenever gwebView has a null pointer but I just don't know how to get the application or cordova context in order to use this function. 我的方法是在gwebView有空指针的情况下在状态栏上显示通用通知但我不知道如何获取应用程序或cordova上下文以使用此函数。

Any help would be appreciated, thanks 任何帮助将不胜感激,谢谢

我在谷歌论坛发现这是插件的错误所以我决定使用Pushwhoosh通知服务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM