AppCache正确设置Android WebView

Bil*_*lly 9 android webview html5-appcache

我想弄清楚哪些是在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");
Run Code Online (Sandbox Code Playgroud)

知道为什么它不起作用的任何想法?

Bil*_*lly 19

找到解决方案:

应用程序缓存路径未正确设置.我现在使用follownig代码来定义路径:

String appCachePath = activity.getCacheDir().getAbsolutePath();
webSettings.setAppCachePath(appCachePath);
Run Code Online (Sandbox Code Playgroud)

而不是旧版本:

webSettings.setAppCachePath("/data/data/"+ getPackageName() +"/cache");
Run Code Online (Sandbox Code Playgroud)

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