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