Since Nougat, Android gives us the option to group our push notifications. On a NotificationCompat.Builder there is a a .setGroup({groupId}) method we can use to specify a group and developers also need to create another group notification to actually encapsulate multiple notifications with the same group id. I've tried to group notifications with the Salesforce SDK but couldn't get what I wanted. Do you know if this is actually possible?
1 Answer
Notification groups are not directly supported by the Marketing Cloud SDK, but you can implement the code necessary for them via the SDK's NotificationManager.NotificationBuilder
. See http://salesforce-marketingcloud.github.io/JB4A-SDK-Android/notifications/interactive-notifications.html if you're unfamiliar with how to use that interface in the SDK
Here is the basic implementation I did to verify that this works:
override fun setupNotificationBuilder(context: Context,
notificationMessage: NotificationMessage): NotificationCompat.Builder {
val groupBuilder = NotificationCompat.Builder(context)
.setContentTitle("My Group")
.setContentText("This is my group")
.setGroup("com.salesforce.marketingcloud.groupA")
.setGroupSummary(true)
.setSmallIcon(R.drawable.ic_notification_icon)
(context.getSystemService(Context.NOTIFICATION_SERVICE) as android.app.NotificationManager)
.notify(0, groupBuilder.build())
return NotificationManager.setupNotificationBuilder(context, notificationMessage)
.apply {
setGroup("com.salesforce.marketingcloud.groupA")
}
}
You'll probably wish to apply more logic to what group each notification is assigned to, but this is the basic idea of how to get it working. You'll also need to be sure to register your NotificationManager.NotificationBuilder
instance when you initialize the SDK.
Additional Reference: https://developer.android.com/training/notify-user/group.html