Android WebView Learning

Source: Internet
Author: User

Android provides a WebView object for web browsing.

1, want to use WebView, first should give permission:internet.

2. WebView Loading HTML Document

3. Call Android object in WebView using javascript: websettings.setjavascriptenabled (TRUE);

public class Jscallandroid extends Activity {WebView mywebview; @Overridepublic void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.main); Mywebview = (WebView) Findviewbyid (R.id.webview );//Here to simplify programming, use the file protocol to load HTML pages in the local assets directory//or, if necessary, use the HTTP protocol to load the HTML page of the remote Web site. Mywebview.loadurl ("file:///android_asset/test.html");//Get WebView Settings object WebSettings websettings = Mywebview.getsettings ();//Turn on JavaScript call websettings.setjavascriptenabled (TRUE);//Expose MyObject object to JavaScript script// This way the JavaScript in the Test.html page can be called by MYOBJ to invoke the MyObject method Mywebview.addjavascriptinterface (new MyObject (This), "MYOBJ");}}

  

Android WebView Learning

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.