现象
前端调用了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)
,避免出现类似问题。