Get Bitmap from Url with HttpURLConnection
//package com.terry.bobobo; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import android.graphics.Bitmap; import android.graphics.BitmapFactory; /** * @author Terry E-mail: yaoxinghuo at 126 dot com * @version create: 2010-10-21 ??01:40:03 */ class HttpUtils { public static Bitmap getImage(URL url) { HttpURLConnection connection = null; try { connection = (HttpURLConnection) url.openConnection(); connection.connect(); int responseCode = connection.getResponseCode(); if (responseCode == 200) { return BitmapFactory.decodeStream(connection.getInputStream()); } else return null; } catch (Exception e) { return null; } finally { if (connection != null) { connection.disconnect(); } } } public static Bitmap getImage(String urlString) { try { URL url = new URL(urlString); return getImage(url); } catch (MalformedURLException e) { return null; } } }