【问题标题】:AppCache correct settings for Android WebViewAndroid WebView 的 AppCache 正确设置
【发布时间】:2015-07-17 09:00:48
【问题描述】:

我正在尝试找出在 android webview 上启用 appcache 的正确设置。我发现了很多关于这个的讨论,但没有一个有效。

鉴于 AppCache 设置正确(它适用于 chrome),我在 webview 上的错误设置如下:

mWebView = (WebView) findViewById(R.id.activity_main_webview);
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setDatabaseEnabled(true);
webSettings.setDomStorageEnabled(true);
webSettings.setAllowFileAccess(true);
webSettings.setAppCachePath("/data/data/"+ getPackageName() +"/cache");
webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
webSettings.setAppCacheEnabled(true);
webSettings.setSupportMultipleWindows(true);
mWebView.setVerticalScrollBarEnabled(false);
mWebView.loadUrl("http://www.myapp.com");

知道为什么它不起作用吗?

【问题讨论】:

  • 你能描述一下什么不起作用吗?您期待什么,而正在发生什么?
  • 我的期望:我的应用离线工作。我得到了什么:该应用无法离线运行,但在移动浏览器上可以正常运行。

标签: android webview html5-appcache


【解决方案1】:

找到解决方案:

应用缓存路径设置不正确。我现在使用以下代码来定义路径:

String appCachePath = activity.getCacheDir().getAbsolutePath();
webSettings.setAppCachePath(appCachePath);

代替旧版本:

webSettings.setAppCachePath("/data/data/"+ getPackageName() +"/cache");

希望对其他开发者有用:)

【讨论】:

  • 它对我很有用,非常感谢,它派上用场了
猜你喜欢
  • 1970-01-01
  • 2012-10-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多