Call Javascript From Cordovaactivity
I'm developing an Android app with Cordova. I have a custom BroadcastReceiver and I want to open the main (and the only one) CordovaActivity in onReceive method. It works properly.
Solution 1:
You need to keep the callback to be able to invoke success/error callback functions after some time has passed within your plugin like this:
within some java class method:
PluginResultr=newPluginResult(PluginResult.Status.NO_RESULT);
r.setKeepCallback(true);
callbackContext.sendPluginResult(r);
// assign callbackContext to class property named callbackContext this.callbackContext = callbackContext;
Then you can pass a string(for instance serialized JSONObject) into a new instance of PluginResult that is returned to your success/error functions as parameter value:
within some java class method:
JSONObject serialized = newJSONObject();
serialized.put("value",1234);
// use assigned class property callbackContext to send some data back to your success callback // because of PluginResult.Status.OK and by passing PluginResult.Status.ERROR you invoke error callbackthis.callbackContext.sendPluginResult(newPluginResult(PluginResult.Status.OK, serialized));
Have a look here of what PluginResult accepts as parameters.
within your plugin.js file:
exec(function(serialized){
console.log(serialized.value);// 1234
}, function(){}, "your plugin name", "your plugin action", { some_arg:'for your plugin'});
Post a Comment for "Call Javascript From Cordovaactivity"