Android webview how to enable local storage and provide JS with the lwindow. localstorage function of html5.

Source: Internet
Author: User
Mwebview = (webview) This. findviewbyid (R. id. webview); websettings settings = mwebview. getsettings (); settings. setjavascriptenabled (true); // settings. setpluginsenabled (true);/*** open the local cache and provide JS calls **/mwebview. getsettings (). setdomstorageenabled (true); // set cache size to 8 MB by default. shocould be more than enoughmwebview. getsettings (). setappcachemaxsize (1024*1024*8); // This next one is crazy. it's the default location for your app's cache // but it didn't work for me without this line. // update: No hardcoded path. thanks to Kevin Hawkins string appcachepath = getapplicationcontext (). getcachedir (). getabsolutepath (); mwebview. getsettings (). setappcachepath (appcachepath); mwebview. getsettings (). setallowfileaccess (true); mwebview. getsettings (). setappcacheenabled (true );

Java navtiveCodeYou only need to set the above parameters to provide local storage for the JS end. Remember that this parameter must be used by API> = 7, that is, android2.1 or later.

Related Article

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.