Android Loading Image from URL (HTTP)

I am writing this tutorial as lot of people are asking me about loading an image into imageview. Just by adding url to ImageView won’t load directly. Instead we need to store the image into cache (temporary location) and attach to ImageView. This can be achieved just by calling couple of lines and don’t forget to add required classes to your project.

1. Create a new project in Eclipse IDE by navigating to File ⇒ New ⇒ Android Project and fill the required details.2. Inorder to load images from an url we first need to store the image in a temporary location and once it is downloaded it should be added to ImageView. To create a temporary file we need to access device external storage. Add required permission to AndroidManifest.xml file.

Hi there! I am Founder at androidhive and programming enthusiast. My skills includes Android, iOS, PHP, Ruby on Rails and lot more. If you have any idea that you would want me to develop? Let’s talk: ravi@androidhive.info

I want to display image in ListVIew From PHP Server or web server .
But I need to set my Enulator HeapSize more than 32 MB. It Generate Errors.
Can I Use Above Code to Display Image in List View From Server.
Help Me.
I am your website great FAN.

Dilip

Fernando

Hi
this tutorial is so good
i read about a lib for developer games in android [libgdx]
can you do tutorials about this?

jaradat

i want to show image in large size so i replace _s by _n but it save it as small,as follow:
String _n=_s.replace(“_s.jpg”, “_n.jpg”);
imageLoader2.DisplayImage(_n, picture);

plz could any one help me?

anonim

break the json into pices until you get the url

waseem ahmad

@anonim …..plzzzz explain how to code to get (username ,…gender,…etc) i m also using json webservic url ,,,,aftr login

Rajsekar

Hi Ravi
This tutorial is very helpful to me please post the dynamic grid view (Images from server) at least please give me a sugeestions

Poongkundran

Please give me code to display multiple images from MYSQL DB with help of php webservice

DataBaseManager

DisplayFromDB();

Nirmal Revar

hi did u got solution of that image blurred ,,,,

Khyati

With the same code when i replace image url it throws FileNotFound Exception . i m stuck with it. Any idea?

Reading image from URL can be performed inside AsynTask as it should not affect the current Activity. Using AysnTask will run downloading image from URL as separate thread.
Regards,
Udhayhttp://programmerguru.com

Ashish Tiwari

Hi, How to store the Images in internal memory of the phone? In this tutorial we are using External memory for cache

Dheeraj

hi , The tutorial helped me a lot…

I have one question though.. Where can I change the size of the image which is downloaded?

Is it possible?

Thanks,

SBE

did not works with images in a listview

guytrx

GREAT TUTORIAL i use it to my app – its work perfect!:)
i m asking your help guys
i use my personal String url – JSON that i downloads about 500 images from my Json!
when i scroll the list view fast i
MUST HAVE A SPINNER PROGRESS BAR IN EVERY ROW IN THE LIST VIEW UNTIL THE IMAGE SHOW/COMPLIT –
PLEASE HELP ME WITH THIS

I also wanted to load images from android phone(internal and external storage) but this image loader download image from http request. How may do it with using internal and external storage.

Wahib

Hi, I followed this tutorial for my app. I populate a listview from an api. Each item of my listview has an image.
After loading a certain amount of image i encounter a
java.lang.OutOfMemoryError: pthread_create (stack size 16384 bytes) failed: Try again

How can I avoid that?

Thanks in advance.

Er B S Choudhary

lot of thanks to androidhive.info….

abhi Gavade

how to send image and text through notification for multiple device

erfan

how can get image bitmap from loader ? i need bitmap so i can show on circle image view
is there any way to get bit map?

Amit Gupta

Thanks a lot androidhive.

DomenicoButtafarro

hi friend , i have need share whit intent the bitmap, can help me? thanks

Tõp Bęãrd.

Thanks

kopilatis

I love you dude

SK

How to do the same if the image source is “https://……” instead of “http://….” ?

kiran

does this works fine in the fragments because iam getting null pointer exception need answer imediately

please help me out. Image from any url not getting loaded and only loader is shown .

Yash Agrawal

@ravi8x:disqus sir if we want to show progress in notification while downloading the image , I am unable to put it properly as either i am getting no notification or at improper time ! Looking forward to your help ! Thank you !.

The reference of the ImageView you passed into the ImageLoader class points to null. In simple words, check your findViewById(R.id.image) part of the code. It must be returning null.

saravanan.a kumar

sir i need ‘n’ number of image url how to load all image using image loader

ABILASH SOMAN

i search image in internet and set into image view how can i save this image into my phone storage /sd card???

anil thakor

Hi Sir I have Problem is that if i change image on firebase through direct or other one upload his new image then when i load this image than its show old image and get from catch memory so please tell me how to notify to catch if i change image on firebase is it because of replace image ? How can i identifie that image is exist on firebase storage or not?

Nishant Makwana

hello sir how can i get image from phpmyadmin and set imageview pls help me

Manisha Khatke

image is not showing in android 6 and above version??

Ajay Saini

how to improve image quality,

Adithya L

I have got ‘out of memory’ exception while loading the image… Could you plz solve this issue?

Ziya khan

Did you code all this by yourself ? Or took sample code and then modified ?

dabhi dhvani

how to api image data set in galleryview in android???please help

Ketan

i used the same code , But i had problem when I give multiple calls simultaneously (in my case I give 10 calls to download 10 images ) the run() method in ImageLoader was called multiple times but the getBitmap wasn’t called same number of times . Only 2 to 3 times getBitmap was called … How to overcome that problem