Android uses the WebView control to load the local HTML, and the data transmits data of data through JS and the background Java to the background CCALLEN

2023-03-18  

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.

source

Random Posts

AndroidUi imitation of the QQ side slide menu effect

Qualcomm Dragonboard 410C MIPI-DIS display function and drive transplant AndyMFC

elasticsearch (4): Install the plug -in IK word segmentation under Linux

Ubuntu realizes the local workbench connection server MySQL database

Python standard, iterative protocol MZP