I am trying to implement bundled notification. After going through lots of tutorials and blogs, I got to know that I have to generate two notifications. One is regular notification, another one is summary notification. I followed everything as stated on those blog posts. Everything seems to work. But I get double notification sound for each notification on Android O. I am not able to fix this issue anyway. I have searched for any similar issue that other people might have faced. But I haven't found anything helpful.
Below are some code snippet of generating notification
Regular Notification
public Notification getSmallNotification(String channelId, String title, String body, Intent intent) {
    PendingIntent resultPendingIntent =
            PendingIntent.getActivity(
                    mContext,
                    ID_SMALL_NOTIFICATION,
                    intent,
                    PendingIntent.FLAG_UPDATE_CURRENT
            );
    NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext, channelId);
    builder.setTicker(title)
            .setWhen(System.currentTimeMillis())
            .setAutoCancel(true)
            .setContentIntent(resultPendingIntent)
            .setContentTitle(title)
            .setContentText(body)
            .setSmallIcon(R.drawable.ic_gw_notification)
            .setColor(ContextCompat.getColor(mContext, R.color.color_bg_splash))
            .setGroup(channelId);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
        builder.setDefaults(Notification.DEFAULT_SOUND);
    }
    Notification notification = builder.build();
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    return notification;
}
Summary Notification
public Notification getSummaryNotification(String channelId, String title, String body) {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext, channelId)
            .setContentTitle(title)
            .setContentText(body)
            .setSmallIcon(R.drawable.ic_gw_notification)
            .setColor(ContextCompat.getColor(mContext, R.color.color_bg_splash))
            .setShowWhen(true)
            .setGroup(channelId)
            .setGroupSummary(true);
    return builder.build();
}
Then I call this two functions simultaneously
notification = gwNotificationManager.getSmallNotification(channelId, title, body, intent);
notificationUtils.getManager().notify(channelId, (int) uniqueId, notification);
Notification summaryNotification = gwNotificationManager.getSummaryNotification(channelId, groupTitle, groupBody);
notificationUtils.getManager().notify(channelId, 0, summaryNotification);
How can I resolve the double sound issue? Any help would be much appreciated!
Another solution is to set in the builder:
setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_SUMMARY)
See documentation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With