4***@qq.com
4***@qq.com
  • 发布:2019-08-01 16:43
  • 更新:2021-07-03 10:54
  • 阅读:8205

uniapp插件开发获取context

分类:uni-app

uniapp的插件扩展中需要集成一个第三方SDK 需要传入context,但是传入mWXSDKInstance.getContext()之后并没有任何效果

下面是原生写法 是没有问题的

然后是混合开发的插件 不能初始化

要怎么获取这个有效的context

2019-08-01 16:43 负责人:无 分享
已邀请:
刘俊朋

刘俊朋

@JSMethod(uiThread=true)
public void initNotificationCallback(JSCallback callback) {
Context context = this.mWXSDKInstance.getContext();
PLInitializer.shared()
.setLog(new ILog()
{
public void info(String message)
{
Log.i("监听", message);
}
}).setNotificationReceivedListener(new OnNotificationReceivedListener(callback)
{
public void onPaymentTypeReceived(Map<String, String> params)
{
Log.i("监听", params.toString());
WeexPluginMonitorModule.this.mWXSDKInstance.fireGlobalEventCallback("onPaymentTypeReceived", WeexPluginMonitorModule.this.mapParam(params));
if (this.val$callback != null)
this.val$callback.invokeAndKeepAlive(params);
}

  public void onUndefineNotificationReceived(String pkg, String content)  
  {  
  }  
});  

}

8***@qq.com

8***@qq.com

可以使用DCLoudApplicationImpl.self().getContext();直接获取 appContext 引一下包

  • p***@163.com

    非常棒

    2022-11-25 18:28

  • 1***@qq.com

    回复 p***@163.com: 你好请问下 你这个成功了吗? 成功了,能否告诉一下 怎么写的 麻烦了

    2023-04-10 17:41

刘俊朋

刘俊朋

@JSMethod(uiThread=true)  
  public void initNotificationCallback(JSCallback callback) {  
    Context context = this.mWXSDKInstance.getContext();  
    PLInitializer.shared()  
      .setLog(new ILog()  
    {  
      public void info(String message)  
      {  
        Log.i("监听", message);  
      }  
    }).setNotificationReceivedListener(new OnNotificationReceivedListener(callback)  
    {  
      public void onPaymentTypeReceived(Map<String, String> params)  
      {  
        Log.i("监听", params.toString());  
        WeexPluginMonitorModule.this.mWXSDKInstance.fireGlobalEventCallback("onPaymentTypeReceived", WeexPluginMonitorModule.this.mapParam(params));  
        if (this.val$callback != null)  
          this.val$callback.invokeAndKeepAlive(params);  
      }  

      public void onUndefineNotificationReceived(String pkg, String content)  
      {  
      }  
    });  
  }

该问题目前已经被锁定, 无法添加新回复