Sandroid Sandroid - 2 years ago 92
Android Question

How to download a image from URL in App

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?

Answer Source

You need to put this permission to access the Internet

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

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);  
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download