How to load Glide cached image in NotificationCompat.Builder.setLargeIcon()?

谁说我不能喝 提交于 2020-01-21 11:48:09

问题


Like this image I am trying to set notification large icon as user profile thumbnail like whatsapp or other chatting apps

I have tried

 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?


回答1:


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

    }
});

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..



来源:https://stackoverflow.com/questions/48967955/how-to-load-glide-cached-image-in-notificationcompat-builder-setlargeicon

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!