java – How to get html page code from webview android?

Question:

Good afternoon. It is necessary to pull out a link to one image from the Android WebView. How can I access html from java code?

Answer:

According to en-SO , with API 19 it's possible like this:

webView.evaluateJavascript(
    "(function() { return ('<html>'+document.getElementsByTagName('html')[0].innerHTML+'</html>'); })();",
     new ValueCallback<String>() {
        @Override
        public void onReceiveValue(String html) {
            Log.d("HTML", html); 
            // code here
        }
});
Scroll to Top