是否有可能访问的WebView缓存?有可能、缓存、WebView

2023-09-05 08:18:08 作者:狗子爱你

我有一个web视图中,我可以访问网页。是否有可能,当我脱机访问,例如到已经previously下载的图片吗? 而且如果可能的话我该怎么办呢?

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?

在此先感谢。

推荐答案

是的,你可以,至少在Android 2.3的低。

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