I built a very simple plugin PhoneGapto start testing how I am going to create some of my own actions on Android.
JavaScript:
function callNativePlugin() {
cordova.exec(nativePluginResultHandler, nativePluginErrorHandler, "Database", "saveAdvertencia", [ 1, "TesteAdv" ]);
}
function nativePluginResultHandler(result) {
alert("SUCCESS: \r\n" + result);
}
function nativePluginErrorHandler(error) {
alert("ERROR: \r\n" + error);
}
Java:
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
if (action.equals("saveAdvertencia")) {
advertenciaDS = new AdvertenciaDS(cordova.getActivity());
callbackContext.sendPluginResult(new PluginResult(Status.OK, new JSONArray("test")));
return true;
}
return false;
}
I need a way to get the result from an action in the same method. It is very difficult to always deal with 3 ways (1 to complete step 1 to determine what the success action will be. 1 to determine what the error action will be.) When you are not really in control when they are called, because it PhoneGapcalls them upon completion of an action
If I need to get some data from the Android Native database:
- Call "cordova.exec" in JavaScript.
- Phonegap will call your plugin.
- 2 : PhoneGap, , . , sucessfull .
- . , 2 , , , PhoneGap . ?