Glide和NotificationCompat.Builder setLargeIcon()

时间:2017-08-11 17:08:31

标签: android bitmap notifications android-notifications android-glide

如何将Glide用于NotificationCompat.Builder setLargeIcon(Bitmap icon)?我已经调查了tutorial,但我不想使用RemoteViews。我还希望在不使用策略Glide.placeholder(int resource)

的情况下使用Glide.error(int resource)Glide.into(new SimpleTarget<Bitmap>(){ ... });

1 个答案:

答案 0 :(得分:0)

这是我使用Glide 4.8.0进行的操作

val notificationBuilder = NotificationCompat.Builder(this, channelId)
            .setSmallIcon(R.drawable.ic_message)
            .setContentTitle("title")
            .setContentText("text")

val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager

val futureTarget = Glide.with(this)
            .asBitmap()
            .load(photoUrl)
            .submit()

val bitmap = futureTarget.get()
notificationBuilder.setLargeIcon(bitmap)

Glide.with(this).clear(futureTarget)

notificationManager.notify(0, notificationBuilder.build())

结果:

enter image description here