• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

How to display images from an URL?

mpi

Lurker
Oct 9, 2018
4
0
I want to display images in my app from a URL and I get the URL of my images from an online database that is "www.example.com/photos" (It's not JSON format, Actually, it's just a folder of multi-images).I've found a few questions and websites about my problem, but they all seem to use JSON format to load images. Now, all I want is how I should retrieve images from this URL with libraries like Valley, Glide,... and after loading them, show in a listview.

Any suggestions or links you have I would greatly appreciate, thank you.
 
There's a similar question here on StackOverflow regarding programmatically loading an image

https://stackoverflow.com/questions/41104831/how-to-download-an-image-by-using-volley/41112901

Code:
ImageView mImageView;
String url = "http://i.imgur.com/7spzG.png";
mImageView = (ImageView) findViewById(R.id.myImage);
...

// Retrieves an image specified by the URL, displays it in the UI.
ImageRequest request = new ImageRequest(url,
   new Response.Listener<Bitmap>() {
       @Override
       public void onResponse(Bitmap bitmap) {
           mImageView.setImageBitmap(bitmap);
       }
   }, 0, 0, null,
   new Response.ErrorListener() {
       public void onErrorResponse(VolleyError error) {
           mImageView.setImageResource(R.drawable.image_load_error);
       }
   });
// Access the RequestQueue through your singleton class.
MySingleton.getInstance(this).addToRequestQueue(request);
 
Upvote 0
There's a similar question here on StackOverflow regarding programmatically loading an image

https://stackoverflow.com/questions/41104831/how-to-download-an-image-by-using-volley/41112901

Code:
ImageView mImageView;
String url = "http://i.imgur.com/7spzG.png";
mImageView = (ImageView) findViewById(R.id.myImage);
...

// Retrieves an image specified by the URL, displays it in the UI.
ImageRequest request = new ImageRequest(url,
   new Response.Listener<Bitmap>() {
       @Override
       public void onResponse(Bitmap bitmap) {
           mImageView.setImageBitmap(bitmap);
       }
   }, 0, 0, null,
   new Response.ErrorListener() {
       public void onErrorResponse(VolleyError error) {
           mImageView.setImageResource(R.drawable.image_load_error);
       }
   });
// Access the RequestQueue through your singleton class.
MySingleton.getInstance(this).addToRequestQueue(request);



Thanks, but it's just one image. I have a lot of images in my URL. What should I do for this?
 
Upvote 0
This works by retrieving one image at a time, by issuing a HTTP request message to the server. You can do this in two ways:-

1. The client must know the names of all images stored on the server, and issue separate HTTP requests for each one.
2. Your server implements a service, which can return a list of images it knows about. Your client then iterates over the list of image names, issuing a HTTP request for each one.
 
Upvote 0
This works by retrieving one image at a time, by issuing a HTTP request message to the server. You can do this in two ways:-

1. The client must know the names of all images stored on the server, and issue separate HTTP requests for each one.
2. Your server implements a service, which can return a list of images it knows about. Your client then iterates over the list of image names, issuing a HTTP request for each one.

So thanks, I can't use the first way because I don't know the names of all images (it may be anything), but for the second way, can you explain more or introduce links that I read it. I'm a beginner in android.
 
Upvote 0
Difficult to answer because I don't know how much you know about web applications. Do you know how to create a RESTful web service? What server side languages do you know?
The way I would do this is to implement a server side REST API to return the contents of a directory of images. PHP is probably the least painful way of implementing this simple service.
 
Upvote 0
Difficult to answer because I don't know how much you know about web applications. Do you know how to create a RESTful web service? What server side languages do you know?
The way I would do this is to implement a server side REST API to return the contents of a directory of images. PHP is probably the least painful way of implementing this simple service.

Unfortunately, I don't know how to create a RESTful web service and I want to learn the server-side language. A way that you think is better for me, Please introduce, I need it. Thanks a lot
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones