'How to show large icon in notification
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.
Solution 1:[1]
1st way(this is what you want)
.setLargeIcon(BitmapFactory. decodeResource (resources , R.drawable. ic_launcher_foreground ))
2st way
.setStyle(NotificationCompat.BigPictureStyle()
.bigPicture(aBitmap)
.bigLargeIcon(null))
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |