服务器之家:专注于服务器技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|Java教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|VB|R语言|JavaScript|易语言|vb.net|

服务器之家 - 编程语言 - Android - android 中 webview 怎么用 localStorage

android 中 webview 怎么用 localStorage

2021-03-26 15:34Android开发网 Android

这篇文章主要介绍了android 中 webview 怎么用 localStorage方法的相关资料,需要的朋友可以参考下

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

?
1
2
3
4
5
6
7
8
9
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);

解决方案:

?
1
2
3
4
5
6
7
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);

这个测试了是可以的

延伸 · 阅读

精彩推荐