Check if file already exists in webview cache andr

2019-02-18 21:34发布

In my app I have an activity with a webview wich loads different images. Before loading the webview, I need to know if the image is already cached in the webview cache. I've found this working solution for 2.3 android devices and lower:

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

from the post "Is it possible to access the WebView cache?" but I would like to find the solution for all devices, so any help will be appreciated... May webview cache directory have changed? Thanks!

1条回答
在下西门庆
2楼-- · 2019-02-18 21:58

Finally I've found a workaround. I save what I need manually in my app cache directory, and when I have to load it again I check if it is inside that directory. That solution works on all android versions.

查看更多
登录 后发表回答