Android Notification Sound

Android Notification Sound

What was missing from my previous code:

Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
builder.setSound(alarmSound);

Different notification sound not working in Oreo

Problem:

It seems Notification Channel issue.

Solution:

Either you should create separate channel, or you should delete your own channel.

Strategy:

1) Create separate channel:

You may select this strategy if you want to persist multiple channels along with various configuration for your app.

To create separate channel, just provide unique channel ID while creating it.

i.e.:

NotificationChannel channel = new NotificationChannel(uniqueChannelId, name, importance);

2) Delete your existing channel and re-create it:

You may select this strategy if you want to persist only one channel along with updated configuration for your app.

To delete your own channel and re-create it, following may work fine:

NotificationManager mNotificationManager = getSystemService(NotificationManager.class);

NotificationChannel existingChannel = notificationManager.getNotificationChannel(channelId);

//it will delete existing channel if it exists
if (existingChannel != null) {
mNotificationManager.deleteNotificationChannel(notificationChannel);
}
//then your code to create channel
NotificationChannel channel = new NotificationChannel(channelId, name, importance);


Related Topics



Leave a reply



Submit