Obtain the content of the webpage when WebView loads HTML

Source: Internet
Author: User

Main. xml is as follows: [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"/> </RelativeLayout> MainActivity: [java] package com. example. testgetwebviewcontent; import android. app. activity; import android. graphics. bitmap; import android. OS. bundle; import android. webkit. webView; import android. webkit. webViewClient;/*** Dmeo Description: * When a WebView loads a webpage, it obtains the content of the webpage. * References :* 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. main); init ();} private void init () {mWebView = (WebView) findViewById (R. id. webView); mWebView. getSettings (). setJavaScriptEnabled (true); mWebView. addJavascriptInterface (new InJavaScriptLocalObj (), "local_obj"); mWebView. getSettings (). setsuppzoom zoom (true); mWebView. getSettings (). setDomStorageEnabled (true); mWebView. getSettings (). setPluginsEnabled (true); mWebView. requestFocus (); mWebView. getSettings (). setUseWideViewPort (true); mWebView. getSettings (). setLoadWithOverviewMode (true); mWebView. getSettings (). setsuppzoom zoom (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) {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 ('

Related Article

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.