Implementing SendActionToNative in JS

2019-09-18 11:56发布

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条回答
Explosion°爆炸
2楼-- · 2019-09-18 12:26

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

查看更多
登录 后发表回答