package com.bwie.test;
import java.io.IOException;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import com.google.gson.Gson;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class SecondActivity extends Activity {
private WebView wv_view;
private String url;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
// 接受
Intent intent = getIntent();
String id = intent.getStringExtra("id");
// 找对象
wv_view = (WebView) findViewById(R.id.wv_view);
url = "http://www.93.gov.cn/93app/info.do?id=" + id;
new Thread(){
public void run() {
getInfo();
}
}.start();
}
private void getInfo() {
HttpClient httpClient=new DefaultHttpClient();
HttpGet httpGet=new HttpGet(url);
try {
HttpResponse response = httpClient.execute(httpGet);
if (response.getStatusLine().getStatusCode()==200) {
HttpEntity entity = response.getEntity();
String string = EntityUtils.toString(entity);
Gson gson=new Gson();
InfoBean infoBean = gson.fromJson(string, InfoBean.class);
String contenttext = infoBean.contenttext;
//加载数据
wv_view.loadDataWithBaseURL(null, contenttext, "text/html", "utf-8", null);
//设置支持html
wv_view.setWebViewClient(new WebViewClient() {
// 设置webView是否调用系统浏览器加载URL,返回false,代表使用webView加
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}
});
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
};
// 返回上一页
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && wv_view.canGoBack()) {
wv_view.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
}
import java.io.IOException;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import com.google.gson.Gson;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class SecondActivity extends Activity {
private WebView wv_view;
private String url;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
// 接受
Intent intent = getIntent();
String id = intent.getStringExtra("id");
// 找对象
wv_view = (WebView) findViewById(R.id.wv_view);
url = "http://www.93.gov.cn/93app/info.do?id=" + id;
new Thread(){
public void run() {
getInfo();
}
}.start();
}
private void getInfo() {
HttpClient httpClient=new DefaultHttpClient();
HttpGet httpGet=new HttpGet(url);
try {
HttpResponse response = httpClient.execute(httpGet);
if (response.getStatusLine().getStatusCode()==200) {
HttpEntity entity = response.getEntity();
String string = EntityUtils.toString(entity);
Gson gson=new Gson();
InfoBean infoBean = gson.fromJson(string, InfoBean.class);
String contenttext = infoBean.contenttext;
//加载数据
wv_view.loadDataWithBaseURL(null, contenttext, "text/html", "utf-8", null);
//设置支持html
wv_view.setWebViewClient(new WebViewClient() {
// 设置webView是否调用系统浏览器加载URL,返回false,代表使用webView加
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}
});
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
};
// 返回上一页
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && wv_view.canGoBack()) {
wv_view.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
}