Skip to content

Instantly share code, notes, and snippets.

@molcik
Last active July 5, 2018 08:17
Show Gist options
  • Save molcik/456a4363354653ff144172a1c70c10a5 to your computer and use it in GitHub Desktop.
Save molcik/456a4363354653ff144172a1c70c10a5 to your computer and use it in GitHub Desktop.
Cordova Example Android Plugin
package com.filipmolcik.plugin; // This must match with the plugin.xml and package.json
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.json.JSONArray;
import org.json.JSONException;
// Example is the 3rd parameter in javascript part
public class Example extends CordovaPlugin {
@Override // action is the 4th parameter, args is the array from 5th parameter in javascript part
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
if (action.equals("YOUR_ACTION_NAME_PARAMETER")) {
// Your black magic comes here
return true;
}
return false; // Returning false results in a "MethodNotFound" error.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment