android webview 中localStorage无效的解决方法

2022-10-19,,

这篇文章主要介绍了android webviewlocalStorage无效的解决方法,本文直接给出解决方法实现代码,需要的朋友可以参考下

我在 android里面 使用html5的 localStorage
为什么存不进去也读不出来呀?
网上搜了好多都没效果

复制代码 代码如下:
mainWebView = (WebView)this.findViewById(R.id.mainWebView);
        WebSettings settings = mainWebView.getSettings();
        settings.setJavaScriptEnabled(true);
        settings.setAllowFileAccess(true);
        settings.setDatabaseEnabled(true);
         String dir = this.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();  
        settings.setDatabasePath(dir);  
        settings.setDomStorageEnabled(true);
        settings.setGeolocationEnabled(true);

解决方案:
复制代码 代码如下:
mWebView.getSettings().setDomStorageEnabled(true);  
mWebView.getSettings().setAppCacheMaxSize(1024*1024*8); 
String appCachePath = getApplicationContext().getCacheDir().getAbsolutePath(); 
mWebView.getSettings().setAppCachePath(appCachePath); 
mWebView.getSettings().setAllowFileAccess(true); 

mWebView.getSettings().setAppCacheEnabled(true);

这个测试了是可以的

您可能感兴趣的文章:

  • 移动端使用localStorage缓存Js和css文的方法(web开发)
  • android 中 webview 怎么用 localStorage
  • HTML5 WebStorage(HTML5本地存储技术)
  • 详解web存储中的storage

《android webview 中localStorage无效的解决方法.doc》

下载本文的Word格式文档,以方便收藏与打印。