In front of the mobile phone browser, often used, JS Web page and Java communication between each other.
Write a simple example.
1, Js and activity communication
browseractivity. s Howsource ("parameter");
Red: The class that represents the call
Blue: Method name for code table substitution
Black: The parameter that represents the call
JS can use this method to carry parameters with Android communication
Inside the Browseractivity.class.
@JavascriptInterface//This sentence must be added, otherwise it will not be called
pubic void Howsource (String param) {
SYSTEM.OUT.PRINLT ("Out string:" +param);
}
2. Activity and JS Communication
Javascript:updateguide ("parameter");
That is: JS, just provide the corresponding method, the activity will carry the corresponding parameters, to access the JS method.
Multiple parameters can be distinguished by separating them, or by other separators.
Android WebView JS and Java communicate with each other