Create a gist now

Instantly share code, notes, and snippets.

Enabling HTML5 AppCache in Android Webview programatically.
private void enableHTML5AppCache() {
webView.getSettings().setDomStorageEnabled(true);
// Set cache size to 8 mb by default. should be more than enough
webView.getSettings().setAppCacheMaxSize(1024*1024*8);
// This next one is crazy. It's the DEFAULT location for your app's cache
// But it didn't work for me without this line
webView.getSettings().setAppCachePath("/data/data/"+ getPackageName() +"/cache");
webView.getSettings().setAllowFileAccess(true);
webView.getSettings().setAppCacheEnabled(true);
webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
}
@shichaosong

thanks.

@avinashlegendkiller

Thanks a lot 😄

@EpocDotFr

Or you can simply:

File dir = getCacheDir();

if (!dir.exists()) {
  dir.mkdirs();
}

webView.getSettings().setAppCachePath(dir.getPath());
@salahzidi

Does this work, even if the appCache is not set in the html5 app?

@sud007
sud007 commented Nov 6, 2015

doesn't make any difference for my usage. Still issues with HTML5 page load.

@pkhutal
pkhutal commented Nov 16, 2015

Hello,
I am trying to call webpage in webview with feature that if user is already login it should redirect to website else on the login page.but this thing work fine on browser but not on webview .please suggest me for this.
Thank you.

@Enlac
Enlac commented Dec 7, 2015

@salahzidi it's programming not magic, of course you need to set it on your HTML5 file, it just allows webview to support it

@ArcherBG

You have to check for internet connectivity before telling to load from cache

@fabsk7
fabsk7 commented Aug 22, 2016

thanks!!! a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment