Skip to content

Instantly share code, notes, and snippets.

Last active October 5, 2023 11:39
Show Gist options
  • Save jaydeepw/3594828 to your computer and use it in GitHub Desktop.
Save jaydeepw/3594828 to your computer and use it in GitHub Desktop.
Enabling HTML5 AppCache in Android Webview programatically.
private void enableHTML5AppCache() {
// Set cache size to 8 mb by default. should be more than enough
// 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");
Copy link


Copy link

Thanks a lot 😄

Copy link

Or you can simply:

File dir = getCacheDir();

if (!dir.exists()) {


Copy link

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

Copy link

sud007 commented Nov 6, 2015

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

Copy link

pkhutal commented Nov 16, 2015

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.

Copy link

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

Copy link

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

Copy link

fabsk7 commented Aug 22, 2016

thanks!!! a lot!

Copy link

Did anybody found that the Application Cache path is not in the path which setted in setAppCachePath funciton("/data/data/"+ getPackageName() +"/cache"),but it was in data/data/packagename/app_webview/Application Cache on Kitkat?

Copy link

it works, thanks

Copy link

yale8848 commented Nov 3, 2017

appcache method will deprecated, you can look at this lib , hope help you

Copy link

Thanks, It solved my issue. I was trying to show angular component inside webview but It was not showing, after I get to know that Angular requires html5 support, adding this code help me to solve issue

Copy link

thank you brooooooo. thats fucking awesome

Copy link

It's good, but some apps or android versions can change this path. Then, use "getFilesDir()", instead of "data/data".

webView.getSettings().setAppCachePath(getFilesDir() + getPackageName() +"/cache");

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