Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Actually this question has many answers. Here are 2 of them : </p> <ul> <li>This first is almost the same as yours, I guess we got it from the same tutorial.</li> </ul> <hr> <pre><code>public class TestActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.webview); final WebView webview = (WebView) findViewById(R.id.browser); webview.getSettings().setJavaScriptEnabled(true); webview.addJavascriptInterface(new MyJavaScriptInterface(this), "HtmlViewer"); webview.setWebViewClient(new WebViewClient() { @Override public void onPageFinished(WebView view, String url) { webview.loadUrl("javascript:window.HtmlViewer.showHTML" + "('&lt;html&gt;'+document.getElementsByTagName('html')[0].innerHTML+'&lt;/html&gt;');"); } }); webview.loadUrl("http://android-in-action.com/index.php?post/" + "Common-errors-and-bugs-and-how-to-solve-avoid-them"); } class MyJavaScriptInterface { private Context ctx; MyJavaScriptInterface(Context ctx) { this.ctx = ctx; } public void showHTML(String html) { new AlertDialog.Builder(ctx).setTitle("HTML").setMessage(html) .setPositiveButton(android.R.string.ok, null).setCancelable(false).create().show(); } } } </code></pre> <p>This way your grab the html through javascript. Not the prettiest way but when you have your javascript interface, you can add other methods to tinker it.</p> <hr> <ul> <li>An other way is using an HttpClient like <a href="https://stackoverflow.com/questions/3479833/is-it-possible-to-get-the-html-code-from-webview">there</a>.</li> </ul> <p>The option you choose also depends, I think, on what you intend to do with the retrieved html...</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload