HttpURLConnection从网上下载图片
2016-07-21 17:44
453 查看
public class HttpThread extends Thread { private final String url; private Handler handler; public WebView webView; public ImageView imageView; public HttpThread(String url, WebView webView, Handler handler) { this.url = url; this.webView = webView; this.handler = handler; } public HttpThread(String url,ImageView imageView,Handler handler) { this.imageView=imageView; this.url =url; this.handler=handler; } @Override public void run() { URL httpUrl = null; try { httpUrl = new URL(url); HttpURLConnection conn = (HttpURLConnection) httpUrl.openConnection(); conn.setReadTimeout(5000); conn.setRequestMethod("GET"); conn.setDoInput(true); conn.connect(); InputStream in=conn.getInputStream(); final Bitmap bitmap= BitmapFactory.decodeStream(in); handler.post(new Runnable(){ @Override public void run() { imageView.setImageBitmap(bitmap); } }); } catch (IOException e) { e.printStackTrace(); } } }
相关文章推荐
- 全面理解HTTP
- TCP/IP模型概述
- Windows Server 2012 虚拟化实战:网络(二)
- iOS NSURLCache(网络缓存)
- WIN764位 如何安装Microsoft LoopBack Adapter(Oracle10g安装时如何通过网络检测)---亲测可用
- 用Node.js创建自签名的HTTPS服务器
- http状态码有哪些?代表什么意思?(查询手册而已)
- 在github上传项目遇到的问题(error: failed to push some refs to 'https://github.com/CrazyDony/text.git')
- com.squareup.okhttp.Interceptor
- Windows Server 2012 虚拟化实战:网络(二)
- OKHttp使用详解及源码解析
- 浅析HTTP协议
- HTTP Header 详解
- MySQL 中NULL和空值的区别 (转载 http://blog.sina.com.cn/s/blog_3f2a82610102v4dn.html)
- Ajax那些事儿
- Mac本不用连接网线,模拟ipv6网络环境
- HTTP的通信的发送请求,接受请求响应包含哪些内容?OC中是怎样实现的?
- 计算机网络之网络基础
- 利用OpenCV读取大华网络摄像头
- HttpWebRequest介绍