Breaking News
Home / Android / Android Snippets / How to load an remote image as a Drawable in Android?

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;
    }<!>

[pb_builder]

Check Also

How to check if an Android device can connect to Internet?

The following code snippet shows how to check if an Android device can connect to …

Leave a Reply