In an Android WebView
, I would like to display websites and download the full HTML with all images from those websites to the device's storage.
As the WebView
downloads all assets of a page in order to be able to display it, it would be redundant work if I loaded the page in the WebView
and afterwards download the HTML and images again, right?
So I thought you could maybe access the contents that the WebView
downloaded and just copy them to the device's storage. Is this possible?
According to this page, you can set up JavaScript interfaces and then call some JavaScript statements like this:
webView.loadUrl("javascript:doSomething()");
So I could get the page's HTML if I just used JavaScript's document.innerHTML
or document.getElementById('theID').innerHTML
.
And for the images, is there an easier solution than to use JavaScript? The problem is that I don't just want the URLs but the loaded resources. The WebView did already download all assets, so the question is if it exposes access to them in some way.
As described in this question, it seems to be possible to get images using context menu events. (Maybe even background images.) But is there a solution that does not require user actions and saves all images in batch, preferably without downloading them once more?