欢迎来到代码驿站!

Android代码

当前位置:首页 > 移动开发 > Android代码

android webview 中localStorage无效的解决方法

时间:2021-04-21 09:38:49|栏目:Android代码|点击:

我在 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);


这个测试了是可以的

上一篇:使用 Swift 语言编写 Android 应用入门

栏    目:Android代码

下一篇:Android获取照片、裁剪图片、压缩图片

本文标题:android webview 中localStorage无效的解决方法

本文地址:http://www.codeinn.net/misctech/105781.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有