How can I load an archived webpage properly in Android?

好久不见. 提交于 2019-12-10 21:37:14

问题


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?


回答1:


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).

If you're trying to save the HTML contents of the page onto your device, there is a method described here.

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.



来源:https://stackoverflow.com/questions/14364501/how-can-i-load-an-archived-webpage-properly-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!