在我的应用程序,当在web视图按钮用户点击,一个PhoneGap的插件会被调用来触发的AsyncTask从互联网上下载文件。现在,我希望在AsyncTask的完成发送信号回JavaScript的一部分。但我不知道该怎么做,因为我的插件已经寄东西回来的AsyncTask完成之前。有谁知道我可以不用插件在PhoneGap的通知我的JavaScript的一部分?
in my app, when user click on a button in webview, a phonegap plugin will be called to trigger an asynctask to download file from internet. Now i want to send a signal back to javascript part when the asynctask is finished. But i don't know how to do it, because my plugin had already send something back before the asynctask is finished. Does anyone know how i can notify my javascript part without plugin in Phonegap?
我也问PhoneGap的谷歌集团这个问题,这里是西蒙·麦克唐纳的回应。它完美对我来说:
I also asked this question in Phonegap Google Group, here is response of Simon Mac Donald. It works perfectly for me:
您可以通过使用插件API很容易地处理这种情况。它 在核心API项目连接和电池实现。什么,你 需要做的是:
You can handle this situation by using the Plugin API quite easily. It is implemented in the core API items Connection and Battery. What you need to do is:
1)在你的插件中的execute()方法保存你的callbackId。
1) In your execute() method of your plugin save the callbackId you get.
2)返回一个NO_RESULT插件的结果,并设置保持回调ID为true。
2) Return a NO_RESULT plugin result and set keep callback id to true.
PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT);
pluginResult.setKeepCallback(true);
return pluginResult;
3)当你异步Java方法完成后返回另一个插件的结果是这样的:
3) When you async java method finishes return another plugin result like this:
PluginResult result = new PluginResult(PluginResult.Status.OK, data);
result.setKeepCallback(false);
this.success(result, this.myCallbackId);
就像我说的,你可以看看code在GitHub上,看看我们是如何使用这种用于连接和电池。
As I said, you can look at the code in GitHub to see how we are using this for Connection and Battery.
上一篇:Android的HttpClient的挂在第二次请求到服务器(连接超时)挂在、服务器、Android、HttpClient
下一篇:DownloadManager.ACTION_DOWNLOAD_COMPLETE广播接收机接收相同的下载ID具有不同的下载状态在Android中不止一次接收机、状态、不同、DownloadManage