Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.io.InputStream;

import java.net.URL;
import java.net.URLConnection;

import android.graphics.Bitmap;

import android.graphics.BitmapFactory;

import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;

import android.util.Log;

public class Main {
    public static Drawable GetUrlDrawable(String url) {
        try {
            URL aryURI = new URL(url);
            URLConnection conn = aryURI.openConnection();
            InputStream is = conn.getInputStream();
            Bitmap bmp = BitmapFactory.decodeStream(is);
            return new BitmapDrawable(bmp);
        } catch (Exception e) {
            Log.e("ERROR", "urlImage2Drawable failed with image url at " + url, e);
            return null;
        }
    }
}