0

I want to load all images from one link

public final class Constants {

    public static final String[] IMAGES = new String[] {
    // Heavy
    "http://domin.com/files/asmabanat/*.jpg", //load all images in this link : *.jpg (1.jpg - 2.jpg ..atc) OR load all images in one web page .

    };

    private Constants() {
    }
}

How can I do this ?

Josh Crozier
  • 233,099
  • 56
  • 391
  • 304
user3245604
  • 79
  • 1
  • 6

1 Answers1

0

Unless you do your own method that generate URLs and try them one by one (which I think is not affordable at all), I think this is not possible to do what you want (as you neither can do that in other environments).

---- EDIT ----

Here would be an example of the mechanism to test whether an URL exists or not.

int counter = 0;
boolean keep_loading = true;

while (keep_loading) {
  final URL url = new URL("http://domin.com/files/asmabanat/" + counter + ".jpg");
  HttpURLConnection huc = (HttpURLConnection) url.openConnection();
  int responseCode = huc.getResponseCode();

  if (resposeCode != 404) {
    // This would mean that the image exists
    // Here you have to do the Lazy Loading of that image
    // You may find a good example of Lazy Loading of images
    // at this URL: http://stackoverflow.com/questions/541966/how-do-i-do-a-lazy-load-of-images-in-listview

    ...
    counter++;
  }
  else {
    // This means the URL returned a 404 error, which means your last image
    // was the last that exists, so you just get out of the loop
    keep_loading = false;
  }
}
nKn
  • 13,691
  • 9
  • 45
  • 62
  • Even if i owned the site , and I'll put images digital sequence (1.jpg - 2.jpg - 3.jpg ...atc )? – user3245604 Feb 02 '14 at 22:47
  • If you know how your images are stored, that changes the thing. You would need to construct the URL generator (in your case, a number generator which can be easily implemented by a `for` loop, specifying `i.jpg`) and download them. As it seems to be, I strongly recommend using Lazy loading (an example here http://stackoverflow.com/questions/541966/how-do-i-do-a-lazy-load-of-images-in-listview) – nKn Feb 02 '14 at 22:49
  • But that will not allow me to add images in the future – user3245604 Feb 02 '14 at 22:57
  • You can make run your method until the first http request returns a 404 error (not found). That means that the last of your images was the last of your server. So next time, if you add 5 more images, they will be processed until the first 404 error, this way you assure yourself you're processing all images within your server. – nKn Feb 02 '14 at 22:59
  • can you give me an example of a simple code . thank you – user3245604 Feb 03 '14 at 13:42