GVillani82
GVillani82

Reputation: 17429

Downloading and showing images in Android

I want download some images from an android application, and then show these images.

I want know where I have to put my downloaded images and how to refer to them in order to show them, for example using them as background of a View object.

Upvotes: 0

Views: 186

Answers (1)

Jong
Jong

Reputation: 9125

Here is an example of downloading an image from a URL and showing it in an ImageView.

This is the download method:

void downloadFile(String fileUrl) {
try{
  InputStream is = (InputStream) new URL(fileUrl).getContent();
  Drawable d = Drawable.createFromStream(is, "src name");
  imgView.setImageDrawable(d);            
    } catch (IOException e) {
        e.printStackTrace();                
    }

}

Upvotes: 3

Related Questions