我正在编写一个将与自定义硬件设备通信的PhoneGap应用程序。这将通过第三方提供的本地库来完成。
要调用本机库,我将编写一个PhoneGap插件。我不知道如何从我的Android代码中将中间结果发送回我的JavaScript代码。有没有办法做到这一点(例如通过cordova.getActivity())或者我是否需要通过JavaScript方面的某种轮询来捏造它?
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
//Start long running process
//Send feedback to PhoneGap Javascript code
//Do more stuff
callbackContext.success("Final result");
return true;
}
答案 0 :(得分:2)
通过使用PluginResult并将KeepCallback设置为true,可以将多个结果发送给成功的JavaScript回调。
PluginResult progressResult = new PluginResult(PluginResult.Status.OK, "Interim 1");
progressResult.setKeepCallback(true);
callbackContext.sendPluginResult(progressResult);