嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元微信扫码支付:2 元
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
【Android实现图片查看器网页原代码查看】
public class Html_yuanma_chakanqiActivity extends Activity {
protected static final int SUCCESS=1;
protected static final int ERROR=2;
private EditText et_path;
private TextView tv_result;
private Handler handler = new Handler(){
public void handleMessage(android.os.Message msg){
super.handleMessage(msg);
switch(msg.what){
case SUCCESS:
String result=(String) msg.obj;
tv_result.setText(result);
break;
case ERROR:
Toast.makeText(Html_yuanma_chakanqiActivity.this, "获取失败", 0).show();
break;
}
};
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
et_path=(EditText) findViewById(R.id.et_path);
tv_result=(TextView) findViewById(R.id.tv_result);
}
public void click(View view){
final String path=et_path.getText().toString().trim();
//访问服务器获取html信息
new Thread(){
public void run(){
try {
URL url=new URL(path);
HttpURLConnection conn =(HttpURLConnection)url.openConnection();
conn.setRequestMethod("GET");
conn.setConnectTimeout(5000);
int code=conn.getResponseCode();
if(code==200){
InputStream is=conn.getInputStream();
//把流的内容转成字符
String result=StreamTools.readStream(is);
//tv_result.setText(result);//修改ui操作 子线程
Message msg= new Message();
msg.what=SUCCESS;
msg.obj=result;
handler.sendMessage(msg);
}
} catch (Exception e) {
e.printStackTrace();
Message msg= new Message();
msg.what=ERROR;
handler.sendMessage(msg);
}
}
}.start();
}
}