Quantcast
Viewing all articles
Browse latest Browse all 35

How to load an remote image as a Drawable in Android?

Loading an remote image from a online server accessible via a URL as Drawable is very straightforward.

// Utililty Method

public static Drawable loadImageAsDrawable(String url) {
    try {

        // open the stream
        InputStream is = (InputStream) new URL(url).getContent();

        String imageName = "xyz";
        Drawable draw = Drawable.createFromStream(is, imageName );
        return draw;
    } catch (Exception e) {
      // something went wrong

       return null;
    }


Viewing all articles
Browse latest Browse all 35

Trending Articles