Android Load Image from URL (Internet) Example

If you are developing a live android application then you will surely need to load image from URL or internet and set it into ImageView. You will find various methods to do this, but all those methods are difficult to understand. In this tutorial I am sharing the simplest way to fetch image from internet.

For doing this we first create an object of URL class and pass this object to decodeStream() method of BitmapFactory class. decodeStream() method decode an input stream into a bitmap. Finally we set this bitmap image into ImageView using setImageBitmap() method.

You should always keep in mind that network related work must be done using AsyncTask class. It is a class used to perform task in background. We will show a progress dialog until the image is loading.


Android Load Image from URL (Internet) Example

Create a new project with application name Android Example and package name thecrazyprogrammer.androidexample

Now add following code in respective files.



As we are using internet so we need to add internet access permission. Add following line of code to AndroidManifest.xml.





Android Load Image from URL (Internet) Example 1

Android Load Image from URL (Internet) Example 2

We have used an AsyncTask here to perform the loading operation. AsyncTask make your code a bit longer. If you want to simply it more you can use a 3rd party libraries like volley or picasso for android

In case you are facing any difficulty or have any doubts regarding above android load image from url tutorial then feel free to comment below.

Leave a Comment

Your email address will not be published. Required fields are marked *