Last active
October 5, 2023 11:39
-
-
Save jaydeepw/3594828 to your computer and use it in GitHub Desktop.
Enabling HTML5 AppCache in Android Webview programatically.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
thank you brooooooo. thats fucking awesome
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
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