是否有可能访问WebView缓存



我有一个WebView,我可以访问网页。当我离线时,是否有可能访问例如以前下载的图像?如果可能的话,我该怎么做?

是的,你可以,至少对于Android 2.3及更低版本。

如果您想查看整个缓存文件夹,它位于这里:

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

如果您已经知道缓存图像的URL,那么您可以获取实际文件:

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

如果其他人面临这个问题,我有一个类似的问题,我解决它管理(保存和检索)我的应用程序缓存手动。这是我的相关文章

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

最新更新