Android WebView js communicates with java, androidwebview
It is often used as a mobile browser. js web pages communicate with Java.
Write a simple example.
1. Js and Activity Communication
BrowserActivity. showSource ("parameter ");
RED: indicates the called class.
Blue: method name used for code table substitution
Black: indicates the called Parameter
Js can use this method to communicate with Android with parameters.
In BrowserActivity. class
@ JavascriptInterface // This sentence must be added; otherwise, the call fails.
Pubic void howSource (String param ){
System. out. prinlt ("out string:" + param );
}
2. Activity and js Communication
Javascript: updateGuide ("parameter ");
That is, in js, you only need to provide the corresponding method. Activity will carry the corresponding parameters to access the Js method.
Multiple parameters can be used or separated by other delimiters.