Check if file exists in web browser

In my application, I have a webview activity that loads different images. Before loading a web view, I need to know that the image is already cached in the web view cache. I found this working solution for 2.3 Android devices and below:

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 message “ Is it possible to access the WebView cache? ”, but I would like to find a solution for all devices, so any help would be appreciated ... Can the web browsing cache directory change? Thanks!

+3
source share
1 answer

Finally, I found a workaround. I save what I need manually in my application cache directory, and when I need to load it again, I check to see if it is inside this directory. This solution works on all versions of Android.

0
source

All Articles