I'm developing a Cordova plugin for an Android application, I read all documentation on Oracle website but I don't understand how i can create custom plugin and use it.
1) I have created a Cordova project which I insert a custom library (jar), this library allow to me to use some customized functions.
My cordova project, that contains a custom library 2) Now i have to create a plugin in cordova that "call" a function inside my library, to do this i have create a new folder in plugins "cordova-plugin-ldm" inside two new folder "src/Android/" and "www".
In src/android i created my java file:
public class MYCLASS extends CordovaPlugin {
protected void pluginInitialize() {
}
public boolean execute(String action, JSONArray args, CallbackContext callbackContext)
throws JSONException {
if (action.equals("alert")) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
TestConnection ts = new TestConnection();
JSONObject result = ts.TestNow();
callbackContext.success(myString);
//callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 0));
return true;
}
return false;
}
}
In www i have created my js :
module.exports = {
greet: function (name, successCallback, errorCallback) {
cordova.exec(successCallback, errorCallback, "Hello", "greet", [name]);
}
};
And in a file "plugin.xml":
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
id="com.acme.plugin.alert"
version="0.0.1">
<name>LDM Plugin</name>
<description>A Cordova plugin for LDM</description>
<engines>
<engine name="cordova" version=">=3.6.0" />
</engines>
<js-module src="www/MYJAVASCRIPT.js" name="MYJAVASCRIPT">
<clobbers target="MYJAVASCRIPT" />
</js-module>
<!-- Android -->
<platform name="android">
<config-file target="res/xml/config.xml" parent="/*">
<feature name="MYNAMEAPP">
<param name="android-package" value="package.ldm" />
</feature>
</config-file>
<source-file src="src/android/MYCLASS.java" target-dir="src/PACKAGE/ldm/plugin/ldm" />
</platform>
Now (i don't know if is it correct, and if it works) but, how i can add (automatically or manually) to my project ?