1. Call JS in Android
If: H5 page has a section of the following JS code
function H5test (str) {xxxx ...}
Android calls in the following ways:
Step one: Start support JS
WebSettings ws = GetSettings ();
Ws.setjavascriptenable (True);
Step Two: Load the Web page
Webview.loadurl (URL);
Step three: Call JS in the Web page, note that the function name in the above JS code in the name of the letter exactly the same
Webview.loadurl ("Javascript:changetitle (' Android call JS ')");
2.JS Call Android
Suppose you click a button on the H5 page to jump to an activity page in your Android code
Step one: Start support JS
WebSettings ws = GetSettings ();
Ws.setjavascriptenabled (TRUE);
Step two: Add the JS interface class to WebView, which encapsulates the native operation. Parameter 2 is the entity class name in JS, which needs to be consistent with the name in JS code.
Webview.addjavascriptinterface (New Jsinterface (), "js2android");
H5 page See js2android will go to the Jsinterface () class to find the appropriate method.
Step three: Write the contents of the interface class
public class jsinterface{@JavascriptInterface //This note must be taken with public void Selectpic () {Intent Intent = new Intent (We Bviewactivity.this,getpicactivity.class); Startactivityforresult (intent,100); }}
Step four: H5 page js corresponding code
function Appselectpic () {javascript:js2android.selectPic ();}
Through the above 4 steps, you can click on the H5 page of a button to jump to the corresponding activity
Android and H5 intermodulation steps