Search code examples
androiduniversal-image-loaderpicassoimageurlimagedownload

Universal image loader and Picasso not loading some of image URLs


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.


Solution

  • 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