0

I'm using a listView in my android app and it has a textView and an imageView. Getting from the web service URLs I want to show into imageView. But Many image URLs is not loading. I tried "Android universal image loader" and "Picasso" for downloading image URLs. I tried these APIs sample applications with my image URLs and same result. The image URLs work. All images are opened in the browser. Why are some images loaded some images not loading? I do not understand why. Thanks for your answers.

realuser
  • 931
  • 2
  • 15
  • 26
  • Can you post more details? For example, some of the URLs - preferable some that work and some that don't. – Intrications Sep 10 '14 at 08:37
  • 1
    Could you show us your stacktrace? UIL displays Log errors for failed images. We can start from there – Pedro Oliveira Sep 10 '14 at 08:37
  • Maybe to much threads operating on bitmaps and therefore somewhere occurs `OutOfMemoryError` Try setting in UIL one thread and put this in your default config `.bitmapConfig(Bitmap.Config.RGB_565)` and `.imageScaleType(ImageScaleType.EXACTLY)` – Mateusz Jablonski Sep 10 '14 at 08:39
  • This is the error in LogCat: E/ImageLoader(13271): java.io.FileNotFoundException: https://m.a***.com/images/catalog/84208/25458.jpg My url begins with www. but it seems m. in logcat – realuser Sep 10 '14 at 08:51
  • Then then server is redirecting your request to the mobile endpoint. – Pedro Oliveira Sep 10 '14 at 08:54
  • I tried four different image download api and none of them was not the solution. @Pedro If the problem is related to the server what should I do? – realuser Sep 10 '14 at 08:59

1 Answers1

4

The problem is that your server is changing the request URL to mobile and the images doesn't exist in the mobile server. Forcing UIL to use another agent should make the server not redirect your request.

Try this with UIL on your DisplayImageOptions

Map<String, String> headers = new HashMap<String, String>();
headers.put("User-Agent","");
options = new DisplayImageOptions.Builder()
.showImageOnLoading(R.drawable.dummyhotelimage)
.showImageForEmptyUri(R.drawable.dummyhotelimage)
.cacheInMemory(true)
.cacheOnDisk(true)
.considerExifParams(true)
.extraForDownloader(headers)
.bitmapConfig(Bitmap.Config.RGB_565)
.imageScaleType(ImageScaleType.EXACTLY)
.build();
ImageLoader.getInstance().init(new ImageLoaderConfiguration.Builder(getActivity()).imageDownloader(new CustomImageDownloader(context)).build());
ImageLoader.getInstance().displayImage(fullImageUrl, holder.img_hotel, options);

Then create a custom ImageDownloader

public class CustomImageDownaloder extends BaseImageDownloader {

    public CustomImageDownaloder(Context context) {
        super(context);
    }

    public CustomImageDownaloder(Context context, int connectTimeout, int readTimeout) {
        super(context, connectTimeout, readTimeout);
    }

    @Override
    protected HttpURLConnection createConnection(String url, Object extra) throws IOException {
        HttpURLConnection conn = super.createConnection(url, extra);
        Map<String, String> headers = (Map<String, String>) extra;
        if (headers != null) {
            for (Map.Entry<String, String> header : headers.entrySet()) {
                conn.setRequestProperty(header.getKey(), header.getValue());
            }
        }
        return conn;
    }
}

Source: https://github.com/nostra13/Android-Universal-Image-Loader/issues/340

Pedro Oliveira
  • 20,442
  • 8
  • 55
  • 82