Before the way through the bridge, there are security issues, Android 4.2 when the repair of this vulnerability, security requirements are relatively high, recommended not to use, please refer to
This blog of mine: http://blog.csdn.net/com360/article/details/38492007
WebView's support for JavaScript is also strong, Google a Java and JavaScript intermodulation example
Throughout the Eclipse ADT Engineering example, here's an emphasis on code: Java Code public class webviewdemo extends activity { private WebView mWebView; private handler mhandler = new handler (); public void oncreate (bundle icicle) { super.oncreate (icicle); Setcontentview (R.layout.webviewdemo); mwebview = (WebView) findviewbyid (r.id.webview); websettings websettings = mwebview.getsettings (); websettings.setjavascriptenabled (true); mwebvIew.addjavascriptinterface (New object () { public void clickonandroid () { mhandler.post (New Runnable ( ) { public void run () { mwebview.loadurl ("Javascript:wave ()"); }           &NBSP}); } }, "Demo"); mwebview.loadurl ("file:///android_asset/demo.html"); } }
The focus here is the Addjavascriptinterface (object Obj,string InterfaceName) method, which binds a Java object to a JavaScript object, The JavaScript object name is InterfaceName, and the scope is global. After the webview is initialized, it is possible to access the bound Java object directly through Javascript:window.demo in the WebView loaded page. To see how it's called in HTML: HTML code
This allows you to invoke the Clickonandroid () method of the Java object in JavaScript, and the Wave () method is an example of Java calling JavaScript.
Here are a few more points of knowledge:
1 to allow WebView to load the Assets,android SDK from the APK file provides a schema, prefixed with "file:///android_asset/". WebView encounters such a schema, it goes to the assets directory in the current package to find content. As the "file:///android_asset/demo.html" above
2 Java objects and methods to be bound in the Addjavascriptinterface method to run another thread, it cannot be run in the thread that constructs him, which is also the purpose of using handler.