1. Add WebView control to the layout file and get WebView objects in Java.
2. Load the local HTML file.
webView.loadUrl(“file:///android_asset/android.html“);
3. Open the JS function.
webView.getSettings().setJavaScriptEnabled(true);
4. Add a JS interactive interface to facilitate the JavaScript code in the HTML layout file that can be accessed directly with the background Java code.
WebView.adddjavaScriptInterface (new contactplugin ()), “contact”); // new class name, the alias used during the contribution of contacta, corresponding to the contactal in Android.html. method.
5. The method of calling JS in Java.
webView.loadurl (“JavaScript: Show (‘” + ARGS + “‘)); // Show’s method of JS can pass data to the front desk.
The effect chart is as follows:
Those who need the source code can go:http://download.csdn.net/detail/caihuajian235/7713891download.