Android WebView get web page data (html)

Source: Internet
Author: User
<span id="Label3"></p><span id="OSC_h2_1"><span id="OSC_h2_1"></span></span><strong><strong>1. activity_main.layout</strong></strong> <pre class="html"><relativelayout xmlns:android= "http://schemas.android.com/apk/res/android"        xmlns:tools= "http://schemas.android.com/tools"       android:layout_ Width= "match_parent"       android:layout_height= "match_parent"        tools:context= ". Mainactivity " >        <WebView           android:id= "@+id/webview"            android:layout_width= "fill_parent"            android:layout_height= "fill_parent"           android:layout_ Centerhorizontal= "true"           android:layout_ Centervertical= "true"            />    &nBsp;</relativelayout> </pre> <p><p><br><br></p></p> <span id="OSC_h2_2"><span id="OSC_h2_2"></span></span>2. Mainactivity.java<pre class="java">package com.example.webviewhtml;import android.app.activity;  import  android.graphics.bitmap;  import android.os.bundle;  import  android.webkit.javascriptinterface;import android.webkit.webview;  import  Android.webkit.webviewclient;  /**  * dmeo description:  *  Get content from this page when WebView loads the page .  *  reference:   * http://www.maxters.net/2012/02/ Android-webview-get-html-source/  */  public class mainactivity extends  Activity {     private WebView mWebView;             @Override       protected void  oncreate (bundle savedinstancestate)  {           super.oncreate (savedinstancestate);           setconTentview (r.layout.activity_main);           init ();       }      private void init () {           mwebview= (WebView)  findviewbyid (R.id.webView);           mwebview.getsettings (). setjavascriptenabled (true);           mwebview.addjavascriptinterface (new  Injavascriptlocalobj (),  "local_obj");           Mwebview.getsettings (). setsupportzoom (true);           Mwebview.getsettings (). setdomstorageenabled (true);           Mwebview.getsettings (). setpluginsenabled (true);           Mwebview.requestfocus ();     &nbsP;     mwebview.getsettings (). Setusewideviewport (true);           mwebview.getsettings (). Setloadwithoverviewmode (true);           mwebview.getsettings (). setsupportzoom (true);           mwebview.getsettings (). Setbuiltinzoomcontrols (true);           mwebview.loadurl ("http://www.baidu.com");           mwebview.setwebviewclient (new webviewclient ()  {                @Override                public void onpagestarted (WebView view,  string url, bitmap favicon)  {               &nbSp;   super.onpagestarted (view, url, favicon);               }                  @Override                public boolean shouldoverrideurlloading (webview view, string  Url)  {                   view.loadurl (url);                   return true;               }                  @Override                Public void onpagefinisHed (webview view, string url)  {                   super.onpagefinished (view, url);                   view.loadurl (" Javascript:window.local_obj.showSource ('

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.