Android的WebView功能:呼叫活动的方法形成的JavaScript接口接口、功能、方法、Android

2023-09-05 02:24:29 作者:Decadence.(颓废.)

时,可以调用的主要活动的方法从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

 
精彩推荐
图片推荐