android WebView加載不出Html的問題

現象

前端調用了localStorage方法,導致打開html失敗。

解決辦法

爲節省空間和安全性考慮,WebView的domStorageEnabled屬性默認爲false。需要設爲true,如下:


WebSettings settings = mWebView.getSettings();
settings.setDomStorageEnabled(true);   
settings.setAppCacheMaxSize(1024*1024*8);  
String appCachePath = getApplicationContext().getCacheDir().getAbsolutePath();  
settings.setAppCachePath(appCachePath);  
settings.setAllowFileAccess(true);  
settings.setAppCacheEnabled(true);

總結

但建議WebView都設置settings.setDomStorageEnabled(true),避免出現類似問題。

參考

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章