Android WebView JS and Java communicate with each other

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.