Cordova.exec function does not start native function

I am trying to make a cordova plugin in an IBM shortcut.

JavaScript:

HelloWorld = {     
  sayHello: function (success, fail, resultType) { 
      Cordova.exec( 
          success, 
          fail, 
          "HelloWorld", 
          "HelloWorld", 
           [resultType]
      );
   }
};

function callFunction() {
    HelloWorld.sayHello(basarili, basarisiz, "sinan");
}

Java:

package com.Cordova1;
import org.apache.cordova.api.CordovaPlugin;
import org.json.JSONArray;

import android.util.Log;
public class HelloWorld extends CordovaPlugin {
    public boolean execute(String arg0, JSONArray arg1, String arg2) {
        Log.d("HelloPlugin", "Hello, this is a native function called from PhoneGap/Cordova!"); 
        return true;
    }
}

When I call the callFunction function, I see that the failure function is working. In addition, I do not see HelloPlugin messages in the log window. What can I do?

+5
source share
4 answers

module 09_3 ApacheCordovaPlugin in the samples really uses the obsolete Plugin class instead of CordovaPlugin. I rewrote the HelloWorldPlugin class in module 09_3 to eliminate the obsolete use of the Cordova plugin API. Sample is working fine.

package com.AndroidApacheCordovaPlugin;

import org.apache.cordova.api.CallbackContext;
import org.apache.cordova.api.CordovaPlugin;
import org.json.JSONArray;
import org.json.JSONException;

public class HelloWorldPlugin extends CordovaPlugin {

    @Override
    public boolean execute(String action, JSONArray arguments,
            CallbackContext callbackContext) throws JSONException {

        if (action.equals("sayHello")) {
            String responseText = "Hello world";
            try {
                responseText += ", " + arguments.getString(0);
                callbackContext.success(responseText);
                return true;
            } catch (JSONException e) {
                callbackContext.error(e.getMessage());
            }
        } else {
            callbackContext.error("Invalid action: " + action);
            return false;
        }
        return false;
    }
}
+4
source

: 1) config.xml? 2) , , CordovaPlugin. :

public boolean execute(String action, JSONArray args, CallbackContext callbackContext)
+2

. 09_3 ApacheCordovaPlugin . , Plugin CordovaPlugin.

import org.apache.cordova.api.Plugin;
import org.apache.cordova.api.PluginResult;

...

public class HelloWorldPlugin extends Plugin {

    public PluginResult execute(String action, JSONArray arguments, String callbackId) {

PluginResult, boolean. , CordovaPlugin, fail. -, WL , , .

0

. 2.4 . , . "cordova.exec", , , PhoneGap.exec, .

I also searched for a definition; The last line of cordova-2.4.0.js says: var PhoneGap = cordova; Ok, Phonegap has been defined, but I don’t know why the cordova doesn’t work.

Thank you for your responses.

0
source

All Articles