I have created one java class which extends CordovaPlugin.
For eg,
public class SampleCardovaPlugin extends CordovaPlugin {
    @Override
    public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
        if (action.equals("echo")) {
            String message = args.getString(0); 
            this.echo(message, callbackContext);
            return true;
        }
        return false;
    }
private void echo(String message, CallbackContext callbackContext) {
    if (message != null && message.length() > 0) { 
        callbackContext.success(message);
    } else {
        callbackContext.error("Expected one non-empty string argument.");
    }
}
}
I'm using cordova2.5.0.
How would I call this plugin from my javascript function? Please do the needful.
You must first register your plugin in the config.xml in the res folder.
Then in the javascript:
cordova.exec(
    function(winParam) {},
    function(error) {},
    "service",
    "action",
    ["firstArgument", "secondArgument", 42, false]);
so in your case
cordova.exec(
    function(data) { console.log(data);},
    function(error) { console.log(error);},
    "SampleCardovaPlugin",
    "echo",
    ["echo"]);
You must also be sure that the device is ready
take a look at http://docs.phonegap.com/en/2.0.0/guide_plugin-development_index.md.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With