除离线浏览的WebView内容? [英] Save webview content for offline browsing?

查看:106
本文介绍了除离线浏览的WebView内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现一个应用程序,允许用户保存   网页包括图像。然后该用户可以再次查看的网页    即使没有网络接入。然而,我发现,没有    这种相关的API这样做。有没有人有想法或经验?任何一个可以提供一些思路或源$ C ​​$ C链接?

I would like to implement an apps that allow users save the webpage including images. Then the users can view the web page again even there is no network access. However, I found that there is no such related API to do so. Does anyone have idea or experience? can any one give some idea or source code link?

推荐答案

至少对于基本的网页,这应该是可能的。

At least for basic pages, this should be possible.

(1)直接下载加载到web视图的HTML文件来代替。然后使用WebView.loadData()或WebView.loadDataWithBaseUrl()到页面加载到视图。不要垃圾的HTML,你以后会需要它。

(1) Download the HTML file instead of loading it directly into the WebView. Then use WebView.loadData() or WebView.loadDataWithBaseUrl() to load the page into the view. Don't trash the html, you'll need it later.

(2)设置你自己的WebViewClient它覆盖了(至少)onLoadResource()。然后保存的页面请求的每一个单一的资源。

(2) Set your own WebViewClient which overrides [at least] onLoadResource(). Then save every single resource requested by the page.

(3)现在你有HTML存储,并且在文件系统的所有必要的文件。搜索通过HTML的绝对路径,你会想用替换功能,使他们无论是相对路径(与本会工作的文件系统),或绝对路径到保存的图片/ CSS /等更新这些。 (在文件系统中)

(3) Now you have the HTML stored, and all the necessary files on the filesystem. Search through the HTML for absolute paths, you'll want to update these with a replacement function so they are either relative paths (and will work on the filesystem) or absolute paths to where you saved the images/css/etc. (on the filesystem)

(4)编写的html文件系统。

(4) Write the html to the filesystem.

我希望这有助于。

另外,你也许可以在网页保存为图像,基本上采取的WebView的屏幕截图。这不会允许复制/粘贴,或点击链接,但它是,如果你需要的是查看此again later的要简单得多。

Alternatively, you could probably save the page as an image, essentially taking a screenshot of the WebView. This wouldn't allow for copy/paste, or clicking of links, but it would be much simpler if all you need is "view this again later".

这篇关于除离线浏览的WebView内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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