My project 10:android webview support HTML5 's offline application feature detailed configuration

Source: Internet
Author: User

Because of the need, I want to andriod on the phone with WebView to my HTML5 project to add a shell, but the first time the project into andriod inside, I test the output of alert altogether is not supported HTML5 Web cache, which makes me very depressed, Find some information on the Internet to see a bit, tested several times finally pass, because I am not engaged in andriod, so it is not detailed introduction, the code to share to everyone:

Mainactivity.java class:

Package com.example.test; Import android.app.Activity; Import Android.content.Context; Import Android.os.Bundle; Import Android.util.Log; Import android.view.KeyEvent; Import android.webkit.WebChromeClient; Import android.webkit.WebSettings; Import Android.webkit.WebStorage; Import Android.webkit.WebView; Import android.webkit.WebViewClient; public class Mainactivity extends Activity {WebView WebView, public void OnCreate (Bundle savedinstancestate) {super.     OnCreate (savedinstancestate);     Setcontentview (R.layout.activity_main);     WebView = (webview) Findviewbyid (R.ID.WEBVIEW1);     Webview.getsettings (). Setjavascriptenabled (True);     Webview.setwebviewclient (New Hellowebviewclient ());     Webview.loadurl ("file:///android_asset/indexfuza.html");     WebSettings settings = Webview.getsettings ();     Settings.setjavascriptenabled (TRUE);     Settings.setdatabaseenabled (TRUE); String DatabasePath = This.getapplicationcontext (). Getdir ("Database", Context.mode_private). GetPath ();     Settings.setdatabasepath (DatabasePath);     WebSettings webseting = Webview.getsettings ();     Webseting.setdomstorageenabled (TRUE); Webseting.setappcachemaxsize (1024*1024*8);//Set the buffer size, I set the 8M String Appcachedir = This.getapplicationcontext (). GetDir     ("Cache", Context.mode_private). GetPath ();     Webseting.setappcachepath (Appcachedir);     Webseting.setallowfileaccess (TRUE);     Webseting.setappcacheenabled (TRUE);        Webseting.setcachemode (Websettings.load_default); Webview.setwebchromeclient (New Webchromeclient () {public void Onexceededdatabasequota (string url, string Databaseiden Tifier, Long Currentquota, long estimatedsize, long Totalusedquota, Webstorage.quotaupdater quotaupdater) {qu         Otaupdater.updatequota (5 * 1024 * 1024); }     }); } public boolean onKeyDown (int keycode, keyevent event) {if (keycode = = keyevent.keycode_back) && webview.ca         Ngoback ()) {webview.goback ();     return true; } return SUPER.ONkeydown (KeyCode, event); } private class Hellowebviewclient extends Webviewclient {public Boolean shouldoverrideurlloading (WebView view, Strin         G URL) {view.loadurl (URL);     return true;  } }}
The Activity_main.xml file inside the layout:

<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android"    xmlns:tools= "http// Schemas.android.com/tools "    android:layout_width=" match_parent "    android:layout_height=" Match_parent "    android:paddingbottom= "@dimen/activity_vertical_margin"    android:paddingleft= "@dimen/activity_ Horizontal_margin "    android:paddingright=" @dimen/activity_horizontal_margin "    android:paddingtop=" @dimen /activity_vertical_margin "    tools:context=". Mainactivity ">    <webview        android:id=" @+id/webview1 "        android:layout_width=" Match_parent "        android:layout_height= "match_parent"/>    </RelativeLayout>
I didn't move anywhere else, so I supported HTML5 Web Storage ....


My project 10:android webview support HTML5 's offline application feature detailed configuration

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.