gpt4 book ai didi

android - Glide 和 NotificationCompat.Builder setLargeIcon()

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:02:58 25 4
gpt4 key购买 nike

如何使用Glide进入NotificationCompat.Builder setLargeIcon(Bitmap icon) ?我已经调查过这个 tutorial但我不想使用 RemoteViews .我也想使用 Glide.placeholder(int resource)Glide.error(int resource)不使用策略 Glide.into(new SimpleTarget<Bitmap>(){ ... });

最佳答案

这是我用 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 =
try {
futureTarget.get()
}
catch (e: InterruptedException) {
//set bitmap fallback in case of glide get fail on a 404 response
}
catch (e: ExecutionException) {
//set bitmap fallback in case of glide get fail on a 404 response
}

notificationBuilder.setLargeIcon(bitmap)

Glide.with(this).clear(futureTarget)

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

结果:

enter image description here

关于android - Glide 和 NotificationCompat.Builder setLargeIcon(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45640430/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com