【问题标题】:Is it possible to access the WebView cache?是否可以访问 WebView 缓存?
【发布时间】:2011-12-10 04:52:51
【问题描述】:

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

提前致谢。

【问题讨论】:

  • 下载是指已查看?如果你下载到手机/平板电脑上,你应该可以去你的画廊看到它们

标签: android caching webview android-webview browser-cache


【解决方案1】:

是的,您可以,至少对于 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

【讨论】:

    【解决方案2】:

    如果其他人遇到这个问题,我也遇到了类似的问题,我手动管理(保存和检索)我的应用缓存来解决它。 Here it is我的相关帖子。

    【讨论】:

    • 这里也一样,为应用程序 webview 实现了我自己的缓存,我用shouldinterceptrequest拦截了所有内容
    • @AnnArbor87,你能告诉我们你在 shouldinterceptrequest 方法中做了什么吗?
    【解决方案3】:

    【讨论】:

    猜你喜欢
    • 2011-09-03
    • 1970-01-01
    • 2019-05-02
    • 2019-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多