读取网络图片
2015-11-04 13:20
603 查看
Handler handler = new Handler() { @Override public void handleMessage(Message msg) { ImageView iv = (ImageView) findViewById(R.id.imageView); if (msg.what == 1) { iv.setImageBitmap((Bitmap) msg.obj); } } };
public void click(View view) throws Exception { new Thread() { @Override public void run() { try { URL url = new URL("http://123.56.111.226:8080/tomcat.gif"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setConnectTimeout(5000); conn.setRequestMethod("GET"); int code = conn.getResponseCode(); if (code == 200) { InputStream is = conn.getInputStream(); Bitmap bitmap = BitmapFactory.decodeStream(is); Message message = new Message(); message.what = 1; message.obj = bitmap; handler.sendMessage(message); } } catch (Exception e) { e.printStackTrace(); } } }.start(); }
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
相关文章推荐
- 用OSSIM轻松分析网络设备日志
- 用OSSIM轻松分析网络设备日志
- 深入理解HTTP协议(转)
- Nginx获取真实IP模块http_realip_module
- 网络之端口的作用
- 网络之子网掩码
- 网络之Ip地址
- 网络之OSI&&TCP/IP比较
- 网络之TCP/IP四层模型
- 网络之OSI七层模型
- HTTP_CONNECTION:Keep-Alive
- 网络安全形势复杂,专利积累成第一要务
- HttpClient设置请求超时和读取超时
- xcode7不允许HTTP传输的过渡办法
- BroadcastReceiver实现动态监测网络是否可用
- iOS NSHttpCookiesStorage的使用
- Android OKHTTP
- http://git.oschina.net/
- 【网络流】最大流:PIGS【EK模板、建图题】
- 虚拟机网络配置区别