Android WebView get HTML source

This may not work on android 4.3 and later because of webview thread security enhancement

In android WebView is the heart when developing Hybrid application. During development of such apps we might need view the source code web page in webview. Here is a piece of code which do the need. The basic idea is install a javascript interface to webview to handle html callback, then call the javascript on webview invoke the method.

first of all setup webview for enabled javascript,assign a custom webclient.


Webclient is responsible for notifying page has loaded and calling the javascript


Javascript interface object for callback here


As you see the above interface just print the html to System.out

4 thoughts on “Android WebView get HTML source”

Comments are closed.