Android and JS Interaction
Set encoding
Webview.getsettings (). Setdefaulttextencodingname ("Utf-8");
Support JS
Webview.getsettings (). Setjavascriptenabled (True);
Parameter 1 for the passed Android object, parameter 2 for passing the object's variable name after JS in the use of variable names for object manipulation
Webview.addjavascriptinterface (New Testjs (), "testobj");
Note the point:
@JavascriptInterface//Android 4.0 or above needs to add this comment on the method called by JS otherwise it cannot be called to, 4.0 the version can be called to
Android Call JS:
string Invokejs = "\" sdffeafsf\ "";//Pass string arguments with double quotation marks
String JavaScript = "javascript:showstring (" + Invokejs + ");";
Webview.loadurl (JavaScript);
JS Call Android Method:
Testobj.jsmethod ("invokeandroid");
Android and JS Interaction