May 20, 2011

Android Loading Image from Server

Hello Guys,


Here I am writing easiest way to download image from server. Following function return Drawable object.  Use drawable object as per your  requirement.




private Drawable LoadImageFromWeb(String url) {
  try {
   InputStream is = (InputStream) new URL(url).getContent();
   Drawable d = Drawable.createFromStream(is, "src name");
   return d;
  } catch (Exception e) {
   System.out.println("Exc=" + e);
   return null;
  }
 }