Proper AppCache Settings for Android WebView

I am trying to figure out which correct settings allow appcache to be enabled in an Android web browser. I debated a lot about this, but none of them worked.

Given that AppCache is installed correctly (it works on chrome), my incorrect settings in web browsing are:

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 why this is not working?

+7
android webview html5-appcache
source share
1 answer

FOUND SOLUTION:

The application cache path is not set correctly. Now I use the follownig code to determine 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 :)

+16
source share

All Articles