手机网页数据返回

package com.news;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;

import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.ByteArrayBuffer;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class Main extends Activity {
	WebView webView;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		webView = (WebView)findViewById(R.id.webView);
        webView.getSettings().setJavaScriptEnabled(true);
    webView.addJavascriptInterface(new InJavaScriptLocalObj(), "local_obj");
   webView.setWebViewClient(new MyWebViewClient());
          webView.loadUrl("http://demo-8.8800.org:7032");
          //webView.loadUrl("http://demo-8.8800.org:7032");
	}

	
	final class MyWebViewClient extends WebViewClient{ 
        public boolean shouldOverrideUrlLoading(WebView view, String url) {  
            view.loadUrl(url);  
            return true;  
        } 
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            //Log.d("WebView","onPageStarted");
            super.onPageStarted(view, url, favicon);
        }   
        public void onPageFinished(WebView view, String url) {
         //   Log.d("WebView","onPageFinished ");
            view.loadUrl("javascript:window.local_obj.showSource('<head>'+" +
                    "document.getElementsByTagName('html')[0].innerHTML+'</head>');");
            super.onPageFinished(view, url);
        }
    }
    final class InJavaScriptLocalObj {
        public void showSource(String html) {
         System.out.println("HTML"+ 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=".Main" >

    
    <WebView
        android:layout_below="@+id/top"
        android:id="@+id/webView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
         />
    

</RelativeLayout>
http://www.mobistyle.cn

你可能感兴趣的:(手机网页数据返回)