Is it possible to access the WebView cache?

 ̄綄美尐妖づ 提交于 2020-01-01 03:24:13

问题


I have a WebView in which I can access to web pages. Is it possible, when I am offline to have access for example to the images that have been previously downloaded? And if it is possible how can I do this?

Thanks in advance.


回答1:


Yes, you can, at least for Android 2.3 and lower.

If you want to see the entire cache folder, it is situated here:

<android cache dir>/<your app package>/cache/webviewCache/

If you already know the URL of the cached image, you can get the actual file so:

String uri = "http://the url of the image that you need";
String hashCode = String.format("%08x", uri.hashCode());
File file = new File(new File(getCacheDir(), "webviewCache"), hashCode);
// if the call file.exist() returns true, then the file presents in the cache



回答2:


If someone else faces this problem, I had a similar issue and I solve it managing(saving and retrieving) my app cache manually. Here it is my related post.




回答3:


CacheManager: http://developer.android.com/reference/android/webkit/CacheManager.html



来源:https://stackoverflow.com/questions/7809483/is-it-possible-to-access-the-webview-cache

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!