软件编程
位置:首页>> 软件编程>> Android编程>> android 中 webview 怎么用 localStorage

android 中 webview 怎么用 localStorage

作者:hebedich  发布时间:2023-04-28 04:38:36 

标签:android,webview,localStorage

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

这个测试了是可以的

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com