简体   繁体   中英

Android Image Download problem with Glide

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);
        }
    }

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM