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

问题描述 投票:3回答:1

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

                }
            });

但它不工作..任何帮助?

android push-notification android-glide android-notification-bar
1个回答
3
投票

如果您使用滑动设置大图标,您还应该通知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使用后台线程加载image..so,然后将图像加载到构建器中...通知管理器已经通知(mainthread),构建器没有大图像。

© www.soinside.com 2019 - 2024. All rights reserved.