如何从URL中的应用程序下载图像 [英] How to download a image from URL in App

查看:83
本文介绍了如何从URL中的应用程序下载图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何,我可以从指定的URL下载图像和ImageView的内部显示它。而没有任何权限来提要求的的manifest.xml 文件?

I'd like to know how I can download an Image from a given URL and display it inside an ImageView. And is there any permissions required to mention in the manifest.xml file?

推荐答案

您需要把这个许可来访问Internet

You need to put this permission to access the Internet

<uses-permission android:name="android.permission.INTERNET" />

您可以试试这个code。

you can try this code.

 String imageurl = "YOUR URL";
 InputStream in = null;

 try {
    Log.i("URL", imageurl);
    URL url = new URL(imageurl);
    URLConnection urlConn = url.openConnection();

    HttpURLConnection httpConn = (HttpURLConnection) urlConn;

    httpConn.connect();

    in = httpConn.getInputStream();

         } catch (MalformedURLException e) {
                e.printStackTrace();
    } catch (IOException e) {
                e.printStackTrace();
    }
    Bitmap bmpimg = BitmapFactory.decodeStream(in);
    ImageView iv = "YOUR IMAGE VIEW";
    iv.setImageBitmap(bmpimg);  
 }

这篇关于如何从URL中的应用程序下载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆