如何在NotificationCompat.Builder.setLargeIcon()中加载Glide缓存的图像? [英] How to load Glide cached image in NotificationCompat.Builder.setLargeIcon()?
问题描述
类似于此图片我正尝试将通知大图标设置为用户个人资料缩略图 像whatsapp或其他聊天应用
Like this image I am trying to set notification large icon as user profile thumbnail like whatsapp or other chatting apps
我尝试过
Glide.with(context)
.asBitmap()
.load(messageNotification.getLargeIcon())
.into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) {
builder.setLargeIcon(resource);
}
});
但是它不起作用.. 有帮助吗?
but it is not working.. Any Help?
推荐答案
如果使用滑行设置大图标,则还应通知NotificationManager onResourceReady(resource, transition)
If you set the large icon using glide..the you should also notify the NotificationManager onResourceReady(resource, transition)
.into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(Bitmap res, Transition<? super Bitmap> t) {
builder.setLargeIcon(res);
yourNotificationManager.notify(id, builder.build());
}
});
这是因为glide使用后台线程来加载图像..因此,在将图像加载到构建器中之前... 通知管理器已被通知(主线程)生成器的图像不大..
This is because glide uses background thread to load image..so before your image is loaded into builder... the notification manager is already notified (mainthread) with builder not having large image..
这篇关于如何在NotificationCompat.Builder.setLargeIcon()中加载Glide缓存的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!