Android Load Image From URL Example

In android we can show image from URL (web).
Here we are going to see about how to load the image from web in simple way.
Example for Android Load Image From Web :-
Add the below code to AndroidManifest.xml for Internet Permission.
[sourcecode language="xml"]
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
Edit your main.xml file
[sourcecode language="xml"]
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/LinearLayout01"
<ImageView android:id="@+id/ImageView01"
android:layout_height="wrap_content" android:layout_width="wrap_content"/>
Edit your java file
[sourcecode language="java"]
import android.os.Bundle;
import android.widget.ImageView;

public class ImageFromUrlExample extends Activity {
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {

ImageView imgView =(ImageView)findViewById(;
Drawable drawable = LoadImageFromWebOperations("");


private Drawable LoadImageFromWebOperations(String url)
InputStream is = (InputStream) new URL(url).getContent();
Drawable d = Drawable.createFromStream(is, "src name");
return d;
}catch (Exception e) {
return null;
output will looks like


What error you got Ron ?

What error you got Ron ?

Hi Ron, If you like to add

Hi Ron,

If you like to add URL example to gallery Example,(as you mentioned in gallery example comment ) you need to do,

First save all the 30 photos URL in a String Array.

See the Image URL Example 16th line ( Drawable drawable = LoadImageFromWebOperations(&rdquo ;”); )

In this we are getting only one drawable. For your program you need 30 drawable.

So create Drawable as Array. And then send the link to LoadImageFromWebOperations() using ’for’ loop for 30 times. Now you will get 30 drawables images in array.

Now see the Gallery example 72nd line ( imgView.setBackgroundResource(GalItemBg); ).

Change that to imagView.setImageDrawable(drawable[arraynumber]);

That’s all.

Now you will get 30 images to Gallery from URL.

Thanks for your code strengis

Thanks for your code strengis :)
To load multiple image in background process it will be very useful.

@Alios, If you get "Unknown


If you get "Unknown Host Exception" then its problem with your network.