2013-06-30 191 views
3

在我的应用程序,我有一个活动,加载不同的图像的web视图。在加载webview之前,我需要知道图像是否已经缓存在webview缓存中。我发现2.3的Android设备,下这个工作解决方案:检查文件是否已经存在于webview缓存android

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 

从岗位“Is it possible to access the WebView cache?”但我想找到的所有设备的解决方案,所以任何帮助将不胜感激。5月的WebView缓存目录已更改? 谢谢!

回答

0

最后我找到了一个解决方法。我在我的应用程序缓存目录中手动保存我需要的内容,并且当我不得不再次加载它时,检查它是否在该目录内。该解决方案适用于所有Android版本。

+2

如何在WebView中手动保存文件? – Xiaozou

+1

你可以在这里发布你的代码吗? –

相关问题