如何在 NotificationCompat.Builder.setLargeIcon() 中加载 Glide 缓存图片?

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

Like this image 我正在尝试将通知大图标设置为用户个人资料缩略图 喜欢 whatsapp 或其他聊天应用程序

我试过了

 Glide.with(context)
            .asBitmap()
            .load(messageNotification.getLargeIcon())
            .into(new SimpleTarget<Bitmap>() {
                @Override
                public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) {
                   builder.setLargeIcon(resource);

                }
            });

但它不起作用.. 有帮助吗?

如果您使用 glide.. 设置大图标,您还应该通知 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..