I have channel group
NotificationChannel notificationChannel = new NotificationChannel(GENERAL_CHANNEL_ID,
GENERAL_CHANNEL_NAME, NotificationManager.IMPORTANCE_DEFAULT);
notificationChannel.enableLights(true);
notificationChannel.setShowBadge(true);
notificationChannel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
notificationManager.createNotificationChannel(notificationChannel);
notificationManager.createNotificationChannelGroup(new NotificationChannelGroup(group, groupName));
notificationManager.notify(code, getNotificationSingle(intent, title, message, group).build());
notificationManager.notify(groupCode, getNotificationGroup(intent, title, message, group).build());
I want to disable the sound of notification if there are more than 2, but I still have the sound.
@TargetApi(26)
public Notification.Builder getNotificationGroup(PendingIntent intent, String title, String body, String group) {
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
return new Notification.Builder(getApplicationContext(), GENERAL_CHANNEL_ID)
.setSmallIcon(R.drawable.ic_qlub_logo_trans)
.setColor(colorForOreo())
.setContentTitle(title)
.setContentText(body)
.setAutoCancel(true)
.setGroup(group)
.setGroupSummary(true)
.setVibrate(new long[]{250, 300, 800})
.setContentIntent(intent);
}
@TargetApi(26)
public Notification.Builder getNotificationSingle(PendingIntent intent, String title, String body, String group) {
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
return new Notification.Builder(getApplicationContext(), GENERAL_CHANNEL_ID)
.setSmallIcon(R.drawable.ic_qlub_logo_trans)
.setColor(colorForOreo())
.setContentTitle(title)
.setContentText(body)
.setGroupAlertBehavior(Notification.GROUP_ALERT_SUMMARY)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setGroup(group)
.setVibrate(new long[]{250, 300, 800})
.setContentIntent(intent);
}
Adding Notification.GROUP_ALERT_SUMMARY
doesn't help. Maybe I am trying to group them in a wrong way, but how can I disable the sound if the group has 2 and more items?
EDIT
Moving .setSound()
from Notification.Builder
to NotificationChannel
instance and setting setOnlyAlertOnce(true)
solved the problem.