如何保存完整的网页并稍后加载以供离线访问 [英] How to save a complete webpage and load later for offline access

查看:30
本文介绍了如何保存完整的网页并稍后加载以供离线访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 WebView 并且想将一些网页保存到内部或外部存储以供离线访问.如果有人已经经历过,请提供一些示例.

I have WebView and wanted to save some web pages to internal or external storage for offline access. Please provide some example if someone has already gone through this.

推荐答案

如果您可以访问服务器端,最好的办法是使用 HTML5 缓存清单,正如我在此处描述的:https://stackoverflow.com/a/14348234/737885

If you have access to the server-side, the best idea would be to use HTML5 cache manifest, as I described it here: https://stackoverflow.com/a/14348234/737885

如果不这样做,您可以尝试按照 HCD 的建议简单地缓存它,但该解决方案取决于 HTTP 标头和其他注意事项,因此它可能不是防弹的.

If you don't, you can try simply caching it as HCD suggested, but that solution depends on HTTP headers, and other considerations, so it might not be bullet-proof.

另一种解决方案是通过 WebViewClient 回调将 WebView 指向组成站点的 URL(请参阅 http://developer.android.com/reference/android/webkit/WebViewClient.html) 并使用 HttpClient 手动下载每个资源.这是三者中唯一的解决方案,它创建了站点的可重复使用的脱机副本.另一个基于 WebView 缓存,因此您只能在同一个 WebView 中使用缓存副本.

An alternative solution would be to point the WebView to the URLs comprising the site by means of the WebViewClient callbacks (see http://developer.android.com/reference/android/webkit/WebViewClient.html) and downloading each resource manually using HttpClient. This is the only solution of the three, which creates a re-usable offline copy of the site. The other are based on the WebView cache so you can only use the cached copies inside the very same WebView.

这篇关于如何保存完整的网页并稍后加载以供离线访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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