我怎样才能在Android的正确加载存档网页? [英] How can I load an archived webpage properly in Android?
问题描述
我要的网页保存到本地。
I want to save the webpage to local.
我发现,有一种方法,以网页保存为归档文件
I found that there is a method to save the webpage as an archive file.
public void saveWebArchive (String filename)
不过,我什么也没得到,但胡言乱语,当我加载该文件。
However, I got nothing but gibberish when I load the file.
WebView webView = (WebView) rootView.findViewById(R.id.webview_layout);
String url = "http://www.yahoo.com";
webView.loadUrl(url);
String path = getFilesDir().getAbsolutePath() + File.separator + "yahoo" + ".html";
webView.saveWebArchive(path);
webView.loadUrl("file://" + path);
我是什么做错了吗?
What am I doing wrong?
推荐答案
WebArchive是一种特殊的文件格式,不能直接读取由的WebView
(即使它是幸福的保存该页面格式)。
WebArchive is a special file format that isn't directly readable by a WebView
(even though it's happy to save pages in that format).
如果你想在页面的HTML内容保存到您的设备,有记载的方法<一href="http://stackoverflow.com/questions/4531062/how-to-programmatically-download-an-html-page-in-android-and-get-its-html">here.
If you're trying to save the HTML contents of the page onto your device, there is a method described here.
如果你真的想要的页面保存为WebArchive文件,请尝试这个帖子。如果需要存储与页面相关联的图形,CSS和其他非文本这种方法可能是有用的。
If you really want to save the page as a WebArchive file, try this post. This approach may be useful if you need to store the graphics, CSS, and other non-text associated with the page.
这篇关于我怎样才能在Android的正确加载存档网页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!