Android WebView缓存 [英] Android WebView caching

查看:93
本文介绍了Android WebView缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个应用程序,其中向用户显示URL列表。为了使其显示得更快,我想检测Wi-Fi状态并在后台加载URL,因此,当用户选择一个URL时,特别是当他们连接到Wi-Fi时,他们会快速看到数据。有办法吗?

I am writing an app where the user is present with a list of URLs. To make it appear more faster, I want to detect the Wi-Fi state and load the URLs in the background, so when the user picks a URL, they are quickly presented the data specially when they are connected to Wi-Fi. Is there a way I can do this?

推荐答案

是,使用 shouldInterceptRequest 。您可以使用它来检测是否具有请求的URL的缓存版本,并将输入流返回到WebView将使用的缓存中,而不是从ze webz加载它。

Yes, using shouldInterceptRequest. Which you can use to detect if you have a cached version of the requested URL and return an input stream to the cache which the WebView will use instead of loading it from ze webz

对于蜂窝版之前的版本,可能可以使用 shouldOverrideUrlLoading ,调用 webview.loadData(datafromcache, text / html, UTF-8); 并返回true。

For versions before honeycomb, it might be possible to use shouldOverrideUrlLoading, calling webview.loadData(datafromcache, "text/html", "UTF-8"); and return true.

这篇关于Android WebView缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆