WebView JS calling Java Local method

Source: Internet
Author: User

WebView = (WebView) This. Findviewbyid (R.id.webview); WebSettings websettings=webview.getsettings (); Websettings.setjavascriptenabled (true); Webview.addjavascriptinterface (NewObject () {/*** This annotation, is 4.0, others can call the local method casually. Lack of security, * above 4.0, in order to prevent others from calling other methods.             Plus it works. * Android4.0 must be added later to invoke *@paramSTR *@paramParentorigin*/@JavascriptInterface Public voidpostMessage (String str, string parentorigin) {Toastutils.showtoast (Getapplicationcontext (), str); }        }, "Parent");        Webview.setscrollbarstyle (View.scrollbars_outside_overlay); //Overwrite WebView default use of third-party or system default browser to open Web page behavior, so that the Web page opened with WebViewWebview.setwebviewclient (Newwebviewclient () {@Override Public Booleanshouldoverrideurlloading (WebView view, String URL) {//The return value is true when the control goes to WebView open, and the system browser or third-party browser is called falseview.loadurl (URL); return true; }        });

WebView JS calling Java Local method

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.