如何在通知中显示大图标
通知的附件图像中有一个小图标和一个大图标。我想创建类似的通知。我可以使用notificationcompat.builder(context).setsmallicon()
来设置小图标。但是我无法设置大图标。任何人都可以帮我吗?
val builder = NotificationCompat.Builder(context)
.setAutoCancel(true)
.setSmallIcon(R.drawable.ic_notification_icon)
.setLargeIcon(BitmapFactory.decodeResource(context.resources, R.drawable.ic_notification_icon))
.setStyle(NotificationCompat.BigPictureStyle()
.bigPicture(BitmapFactory.decodeResource(context.resources, R.drawable.ic_notification_icon))
.bigLargeIcon(BitmapFactory.decodeResource(context.resources, R.drawable.ic_notification_icon)))
.setColor(context.getColor(R.color.colorPrimary))
.setContentTitle(notificationTitle)
.setContentText(notificationText)
.setLights(Color.RED, 1000, 1000)
.setVibrate(longArrayOf(0, 400, 250, 400))
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
.setContentIntent(
PendingIntent.getActivity(
context,
0,
Intent(context, SplashActivity::class.java),
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
)
)
我尝试使用上述代码添加大图标,但它不起作用。
There is a small icon and a large icon in the attached image of a notification. I would like to create a similar notification. I am able to set the small icon using NotificationCompat.Builder(context).setSmallIcon()
. But I am not able to set the large icon. Can anyone please help me with this.
val builder = NotificationCompat.Builder(context)
.setAutoCancel(true)
.setSmallIcon(R.drawable.ic_notification_icon)
.setLargeIcon(BitmapFactory.decodeResource(context.resources, R.drawable.ic_notification_icon))
.setStyle(NotificationCompat.BigPictureStyle()
.bigPicture(BitmapFactory.decodeResource(context.resources, R.drawable.ic_notification_icon))
.bigLargeIcon(BitmapFactory.decodeResource(context.resources, R.drawable.ic_notification_icon)))
.setColor(context.getColor(R.color.colorPrimary))
.setContentTitle(notificationTitle)
.setContentText(notificationText)
.setLights(Color.RED, 1000, 1000)
.setVibrate(longArrayOf(0, 400, 250, 400))
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
.setContentIntent(
PendingIntent.getActivity(
context,
0,
Intent(context, SplashActivity::class.java),
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
)
)
I tried adding the large icon using the above code, but it didn't work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
第一路(这是您想要的)
第2条
1st way(this is what you want)
2st way
我们可以将SVG转换为位图图像并将其设置为通知图标。
We can convert svg to bitmap images and set it to notification icons.