1

I've started to face an issue with Glide Image Download.

My application is running on Glide version 4.8.0 and minSdkVersion 21, targetSdkVersion 26, and compileSdkVersion 28.

The problem is Glide is unable to download an image from Apple News and causes it to lock and crash application. The URL of the image is https://c.apple.news/AgEXQU9SSmFycEhYUUVlSkxKUE52XzN1M1EAMA

The code to execute the image download is:

Glide.with(context)
.setDefaultRequestOptions(getRequestOptionsForImage(item.ContentPersonStatusUpdate.widthURLImageWidth,context.getResources().getDimensionPixelSize(R.dimen.image_height_external_link),context))
.asBitmap()
.load(https://c.apple.news/AgEXQU9SSmFycEhYUUVlSkxKUE52XzN1M1EAMA)
.into(imageViewContent);

public static RequestOptions getRequestOptionsForImage(int width, int height, Context context){
        return  new RequestOptions().skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.AUTOMATIC).override(width,height).placeholder(context.getDrawable(R.drawable.ic_news_thumbnail_loading));
    }

Any idea/solution about this issue? This problem only occurs for Apple News Image URLs.

***UPDATE

I've tried to download image with the code below. Getting no responses, even catch never firing.

new DownloadImageTask(imageViewContent).execute(https://c.apple.news/AgEXQU9SSmFycEhYUUVlSkxKUE52XzN1M1EAMA);


private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
        ImageView bmImage;
        public DownloadImageTask(ImageView bmImage) {
            this.bmImage = bmImage;
        }

        protected Bitmap doInBackground(String... urls) {
            String urldisplay = urls[0];
            Bitmap bmp = null;
            try {
                InputStream in = new java.net.URL(urldisplay).openStream();
                bmp = BitmapFactory.decodeStream(in);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return bmp;
        }
        protected void onPostExecute(Bitmap result) {
            bmImage.setImageBitmap(result);
        }
    }
Zoe
  • 27,060
  • 21
  • 118
  • 148
Serkan Hekimoglu
  • 4,234
  • 5
  • 40
  • 64

1 Answers1

1

Serkan your code is correct except the request option part. i try below code and worked fine:

    String url="https://c.apple.news/AgEXQU9SSmFycEhYUUVlSkxKUE52XzN1M1EAMA";

    RequestOptions requestOptions = new RequestOptions();
    requestOptions.error(R.drawable.img_placeholder);
    Glide.with(context)
            .setDefaultRequestOptions(requestOptions)
            .load(url)
            .into(imgImage);

i try your code too without request option like below:

    Glide.with(context)
            .asBitmap()
            .load(url)
        .into(imgImage);

and worked fine too

when i try to use with your request option code its tell me use @RequiresApi(LOLLIPOP) annotation. may you are testing app in below api and the method doesn't work.

hamed
  • 148
  • 11
  • Thank you for your answer. Code pieces only works on Lollipop as you've noticed. Can you please try to download image from that URL on for example Android 8.1 Oreo which I use on my emulator and cannot download? – Serkan Hekimoglu May 07 '19 at 12:54
  • Putting API Requirement and removing asBitmap() solved the problem. So I'm going to accept your answer. Thank you very much. – Serkan Hekimoglu May 08 '19 at 09:12