时,可以调用的主要活动的方法从web视图对象的JavaScript界面?或者从这个接口访问共享preferences,所以我可以读我的活动数据?我想,让我的活动知道某个特定的JavaScript行为发生。
Is is possible to call main activity's methods from the JavaScript interface of a WebView object? Or to access SharedPreferences from this interface so I could read the data with my activity? I would like to let my Activity know that a specific JavaScript action occured.
是的,JavaScript和应用程序之间的双向沟通,可以通过 WebView.addJavascriptInterface()
。检查这个例子:
Yes, two way communication between JavaScript and your application is possible through WebView.addJavascriptInterface()
. Check this example:
http://android-developers.blogspot.com/2008/ 09 /使用-webviews.html