[英]Android Image Download problem with Glide
I've started to face an issue with Glide Image Download. 我开始面临Glide Image Download的问题。
My application is running on Glide version 4.8.0 and minSdkVersion 21
, targetSdkVersion 26
, and compileSdkVersion 28
. 我的应用程序在Glide版本4.8.0和
minSdkVersion 21
, targetSdkVersion 26
和compileSdkVersion 28
。
The problem is Glide is unable to download an image from Apple News and causes it to lock and crash application. 问题是Glide无法从Apple News下载图像并导致其锁定并崩溃应用程序。 The URL of the image is https://c.apple.news/AgEXQU9SSmFycEhYUUVlSkxKUE52XzN1M1EAMA
图片的网址是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.
只有Apple News Image URL才会出现此问题。
***UPDATE *** 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. Serkan你的代码是正确的,除了请求选项部分。 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. 当我尝试使用您的请求选项代码时,它告诉我使用@RequiresApi(LOLLIPOP)注释。 may you are testing app in below api and the method doesn't work.
你可能正在下面的api测试应用程序,该方法不起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.