package com.example.service;

import java.io.IOException;
import java.io.InputStream; 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 android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.Menu;
import android.widget.ImageView; public class MainActivity extends Activity { static ImageView image;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
image=(ImageView) findViewById(R.id.image);
/* Intent intent=new Intent(this, MyService.class);
startService(intent);*/ new thrad().start(); }
Handler handle=new Handler(){ @Override
public void handleMessage(Message msg) { image.setImageBitmap((Bitmap) msg.obj);
} };
class thrad extends Thread{ @Override
public void run() {
HttpClient http=new DefaultHttpClient();
HttpGet request=new HttpGet("http://dh2.kimg.cn/www/meinv/5/7f/547f54c2a9712b8b2e7be7a5ca2fe5fd-af35e4");
HttpResponse response = null;
try {
response = http.execute(request);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
InputStream in = null;
try {
in = response.getEntity().getContent();

      //String str=EntityUtils.toString(response.getEntity());
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}//服务器返回的数据
Bitmap bitmap=BitmapFactory.decodeStream(in);
Message msg=handle.obtainMessage();
msg.obj=bitmap;
handle.sendMessage(msg);
try {
in.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} }
}

最新文章

  1. bzoj1901
  2. 第二天ci项目规划 数据库设计
  3. ToolBar和DrawerLayout的使用实现侧拉栏抽屉的开闭
  4. Android -- Activity,Fragment lifecycle
  5. 【转载】Ubuntu下SVN安装和配置
  6. json学习系列(6)JSONObject和JSONArray是JDK的集合部分延伸
  7. (转)SqlServer将数据库中的表复制到另一个数据库
  8. CentOS安装中文输入法
  9. Java三大主流框架概述(转载)
  10. Tomcat,Weblogic,WebSphere,JBoss四种服务器简单对比
  11. box-size
  12. HDU 5677 ztr loves substring
  13. Android报错:WindowManager$BadTokenException: Unable to add window -- window has already been added
  14. java工作流引擎Jflow流程事件和流程节点事件设置
  15. 分布式缓存技术之Redis_03分布式redis
  16. [NOI2009]诗人小G(dp + 决策单调性优化)
  17. java之servlet学习基础(二)
  18. 总结 Linux 下安装 PHP 扩展步骤
  19. Confluence 6 数据库连接方式
  20. http-cookie、session、Token

热门文章

  1. PHP Html5上传大文件
  2. JavaScript作用域学习笔记
  3. [转]Oracle 树操作(select…start with…connect by…prior)
  4. 论文笔记之:Dueling Network Architectures for Deep Reinforcement Learning
  5. Vmvare下Ubuntu安装Python3.4
  6. Maven根据不同个环境打包, 获取不同的配置文件等等
  7. 怎么 才能显示Eclipse中Console的全部内容
  8. api接口签名验证(MD5)
  9. 使用-MM生成include指令和依赖生成(make include directive and dependency generation with -MM)
  10. [zz]Lessons from Pixar: Why Software Developers Should Be Storytellers