現象
前端調用了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)
,避免出現類似問題。