Implementing SendActionToNative in JS

戏子无情 提交于 2019-12-12 03:44:16

问题


I have extended CordovaActivity, and implemented WLInitWebFrameworkListener plus BluetoothAdapter.LeScanCallback in native code

public class MainActivity extends CordovaActivity implements WLInitWebFrameworkListener, BluetoothAdapter.LeScanCallback{
  1. Inside this class I have implemented

    @Override
    public void onInitWebFrameworkComplete(WLInitWebFrameworkResult arg0) {
    // if a device is connected launch application
    if(mConnectedGATT.connect()){
        WL.getInstance().addActionReceiver(new ErosReceiver());
        super.loadUrl(WL.getInstance().getMainHtmlFilePath());
    
        }
    else{Log.i(TAG, "Could not connect");}
    }
    
  2. I have added the following to main.js in a function

    WL.App.SendActionToNative ("ReqSlaveList", data);
    
  3. I have created another class MyReceiver

    public class MyReceiver implements WLActionReceiver {
    
  4. Implemented

    public void onActionReceived(String action, JSONObject data) 
    

Now it seems like the OnActionReceived never gets called.


回答1:


I don't think you're supposed to create a new class that implements onInitWebFrameworkComplete. You need to append your code to the existing application main class that already does this (and which MobileFirst Platform relies on).

You can find this application main class in your application's native folder in MobileFirst Studio. That is where you should declare your ActionReceiver. See here: https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/6.3/adding-native-functionality/android-adding-native-ui-elements-hybrid-applications/#action-receiver



来源:https://stackoverflow.com/questions/38301896/implementing-sendactiontonative-in-js

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