How can I load an archived webpage properly in Android?

android, android-webview, mobile

Solution

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.

Problem

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?

Original source