Android Drawable Create getDrawableFromUrl(String url)

Here you can find the source of getDrawableFromUrl(String url)

Description

get Drawable From Url

Declaration

public static Drawable getDrawableFromUrl(String url) throws Exception 

Method Source Code

//package com.java2s;

import java.io.InputStream;
import java.net.HttpURLConnection;

import java.net.URL;

import android.graphics.drawable.Drawable;

public class Main {
    public static Drawable getDrawableFromUrl(String url) throws Exception {
        return Drawable.createFromStream(getRequest(url), null);
    }//from w  ww .j a  v  a 2s  .co m

    public static InputStream getRequest(String path) throws Exception {
        URL url = new URL(path);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("GET");
        conn.setConnectTimeout(5000);
        if (conn.getResponseCode() == 200) {
            return conn.getInputStream();
        }
        return null;
    }
}

Related

  1. loadDrawable(final String imageUrl, final ImageView imageView, final ImageCallback imageCallback)
  2. getDrawableById(Context paramContext, String paramString)
  3. getPressedDrawable(int color)
  4. getDrawableByName(Context ctx, String name)
  5. getDrawable(final Context context, final String packageName, final int resourceID)
  6. drawableToTransitionDrawable( Drawable drawable)