/*
请求服务器一个资源,将其下载到手机显示,显保存到SD卡中。
通过http的get请求连接服务器,(下载只能用GET方式请求)。如果连接成功服务器端自动会往流中写东西,客户
端只要拿到InputStream就能从中拿到数据。
*/
1、从EditText输入框中得到输入的服务器资源路径
String path = et_path.getText().toString().trim();
2、创建URL地址
URL url = new URL(path);
3、获得HttpURLConnection 连接
HttpURLConnection conn =(HttpURLConnection)url.openConnection();
4、设定请求头:请求方式GET和浏览器类型
conn.setRequestMethod("GET");
conn.setRequestProperty("User-Agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)");
5、获取连接响应码,如果成功,下载文件
InputStream is = conn.getInputStream(); //从连接中获取输入流
FileOutputStream fos = new FileOutputStream(file);
byte []buffer = new byte[1024];
int len = 0;
while((len = is.read(buffer))!= -1){
fos.write(buffer,0,len);
}
fos.close();
is.close();
6、从文件中拿到数据,显示在ImageView件中
lv.setImageURI(Uri.fromFile(file));
分享到:
相关推荐
android 将Imageview 将view生成图片后保存到本地相册的实现生成图片后保存到本地相册的实现,android 将Imageview生成图片后保存到本地相册的实现 android 将Imageview生成图片后保存到本地相册的实现, 有需要的朋友...
基于androidStudio开发的App,实现了拍照功能,并能对照片进行剪裁操作,然后回显到imageView控件上。
通过图片的url获取到图片,并显示到imageview中,本实例中选择的图片的百度官网的logo。仅提供一种获取网络图片的方法。
android开发 点击按钮从sd卡选择图片显示在ImageView
android根据url下载图片的网络ImageView
Android ImageView实现是对图片放大后可以局部的拉伸放大,双击放大
The idea of this android library is to give the possibility to display two texts inside the imageitself. These texts could be the title or the description of the image or something else. Also there ...
Android调用系统摄像头拍照并显示在ImageView上
Android imageview,imageswitcher显示SD卡上图片,并彻底解决imageview out of memory,记过这两天多次反复查找资源及测试,可以使用
Android ImageViewEx 支持Gif显示的ImageView Demo.zip
ImageView 图片显示样式的几种类型。android:scaleType是控制图片如何resized/moved来匹对ImageView的size。
RCImageView 自定义圆角ImageView,带边框效果
Android ImageView点击选中后添加边框,详细内容可以到我的博客www.heimizhou.com中了解。
android自定义ImageView实现旋转动画
1.Android的自定义ImageView图标,可以根据自己的需要,设置圆形,椭圆形,长方形,正方形图标; 2.都是需要在导入jar包文件后在xml文件中引入<com.hongye.image.image.CircleImageView/> 圆形 ...
安卓Android源码——ImageViewEx支持Gif显示的ImageView.zip
Android应用源码之imageView1_imageView
安卓Android源码——ImageViewEx 支持Gif显示的ImageView.rar
android 自定义属性实现 ImageView 透明度渐变效果
用于android的Imageview缩放库