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

1

7

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?

Stratfordonavon answered 24/2, 2018 at 21:46 Comment(0)
E
7

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

Etiquette answered 24/2, 2018 at 21:51 Comment(2)
SimpleTarget it is deprecated is there any other solutionCrinoid
@VinitPoojary use CustomTarget<Bitmap>Underlayer

© 2022 - 2024 — McMap. All rights reserved.