title: Read elements in HTML loaded form webview Android
body: <p>I need to read elements from an HTML file. I loaded them from webview but I haven't found the best way to read.</p>
  
  <p>Code: content_html</p>
  
  <pre><code>package com.android.webview;
  
  import android.app.Activity;
  import android.app.AlertDialog;
  import android.app.AlertDialog.Builder;
  import android.content.Context;
  import android.os.Bundle;
  import android.util.Log;
  import android.webkit.WebView;
  import android.webkit.WebViewClient;
  
  public class ViewLink extends Activity {
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
      final WebView browser = (WebView)findViewById(R.id.browser);
      /* JavaScript must be enabled if you want it to work, obviously */
      browser.getSettings().setJavaScriptEnabled(true);
  
      /* Register a new JavaScript interface called HTMLOUT */
      browser.addJavascriptInterface(new MyJavaScriptInterface(), "HTMLOUT");
  
      /* WebViewClient must be set BEFORE calling loadUrl! */
      browser.setWebViewClient(new WebViewClient() {
          @Override
          public void onPageFinished(WebView view, String url)
          {
              /* This call inject JavaScript into the page which just finished loading. */
              browser.loadUrl("javascript:window.HTMLOUT.showHTML('&lt;head&gt;'+document.getElementsByTagName('html')[0].innerHTML+'&lt;/head&gt;');");
  
              /*
              read elements in content_html
              */
          }
  
      });
  
  
      browser.loadUrl("http://vnexpress.net/gl/rss/");
  }
  
  final Context myApp = this;
  Builder builder;
  
  String content_html;
  
  /* An instance of this class will be registered as a JavaScript interface */
  class MyJavaScriptInterface
  {
      @SuppressWarnings("unused")
      public void showHTML(String html)
      {
         builder = new AlertDialog.Builder(myApp);
              builder.setTitle("HTML")
              .setMessage(html)
              .setPositiveButton(android.R.string.ok, null)
          .setCancelable(false)
          .create()
          .show();
              content_html = html;
              Log.i("html", html+" ");
      }
  }
  </code></pre>