i'm trying develop cordova plugin android following tutorial found here: http://www.mat-d.com/site/tutorial-creating-a-cordova-phonegap-plugin-for-android-app/
so far, good. however, i'd know how send data/trigger event in javascript code plugin - example, when user taps icon in native code, i'd javascript something. possible?
so got work follows:
i created private callbackcontext object in plugin:
private callbackcontext callbackcontext;
and stored callbackcontext supplied in execute() method in it:
public boolean execute(final string action, jsonarray args, callbackcontext callbackcontext) throws jsonexception { this.callbackcontext = callbackcontext; }
elsewhere in java code, can access callback , send plugin results it. callback become invalid, however, after it's first triggered, unless keepcallback set true
:
pluginresult pluginresult = new pluginresult(pluginresult.status.ok, "what"); pluginresult.setkeepcallback(true); callbackcontext.sendpluginresult(pluginresult);
this made me happy camper. hope helps else!