I'm trying to figure out which are the correct settings to enable appcache on android webview. I found many discussions about that but none of them worked.
Given that AppCache is set correctly (it works on chrome), my wrong settings on the webview are the following:
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");
Any idea of why it doesn't work?
FOUND THE SOLUTION:
The app cache path wasn't set correctly. I'm now using the follownig code to define the path:
String appCachePath = activity.getCacheDir().getAbsolutePath();
webSettings.setAppCachePath(appCachePath);
Instead of the old version:
webSettings.setAppCachePath("/data/data/"+ getPackageName() +"/cache");
Hope will be useful for other developers :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With