Android Custom Notification Sound in Oreo

To create notification sound you must change the sound in channel in oreo and above.

To set a sound to notifications in Oreo, you must set sound on NotificationChannel and not on Notification Builder itself. You can do this as follows

Uri sound = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + context.getPackageName() + "/" + R.raw.notification_mp3);


        NotificationChannel mChannel = new NotificationChannel("YOUR_CHANNEL_ID",
            "YOUR CHANNEL NAME",

        AudioAttributes attributes = new AudioAttributes.Builder()

        NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID, 

        // Configure the notification channel.
        mChannel.setSound(sound, attributes); // This is IMPORTANT

        if (mNotificationManager != null)

This will set a custom sound to your notifications. But if the app is being updated and the notification channel is used before, it won’t be updated. i.e. you need to create a different channel and set sound to it to make it work. But this will show multiple channels in the notifications section of app info of your app. If you are setting sound to an entirely new channel that is fine, but if you want the channel being used before, you have to delete the existing channel and recreate the channel. To do that you can do something like that before creating channel

if (mNotificationManager != null) {
            List<NotificationChannel> channelList = mNotificationManager.getNotificationChannels();

            for (int i = 0; channelList != null && i < channelList.size(); i++) {

Source : Stackoverflow

Leave a Reply