Different Notification Sound Not Working In Oreo

I am facing some Notification related issue in Oreo Version only. I follow this link and successfully got custom sound after uninstall/install the app as he has suggested.

Now problem is that I want to use two custom sound in my app, For that, I have code like:

private void sendNotification(NotificationBean notificationBean) {
    String textTitle = notificationBean.getTitle();
    String alert = notificationBean.getMessage().getAlert();
    int orderId = notificationBean.getMessage().getOrderId();
    String notificationType = notificationBean.getMessage().getNotificationType();
    String sound = notificationBean.getMessage().getSound();

    Intent intent = new Intent(this, NavigationDrawerActivity.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);

    Uri soundUri;

    if (notificationType.equals("Pending"))
        soundUri = Uri.parse("android.resource://" + getApplicationContext().getPackageName() + "/" + R.raw.sound);
        soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this, getString(R.string.app_name))

    // Create the NotificationChannel, but only on API 26+ because
    // the NotificationChannel class is new and not in the support library
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        CharSequence name = getString(R.string.app_name);
        String description = getString(R.string.app_name);
        int importance = NotificationManager.IMPORTANCE_DEFAULT;

        NotificationChannel channel = new NotificationChannel(getString(R.string.app_name), name, importance);

        AudioAttributes attributes = new AudioAttributes.Builder()

        channel.setSound(soundUri, attributes);

        // Register the channel with the system; you can't change the importance
        // or other notification behaviors after this
        NotificationManager notificationManager = getSystemService(NotificationManager.class);

    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);

    // notificationId is a unique int for each notification that you must define

If I get notificationType = "Pending" then I want to use custom sound, otherwise DEFAULT sound but Here It is playing that sound which is played first-time (When I receive notification first time.).

I am getting this problem in OREO only. In all other devices its working fine.

Any help? Your help would be appreciated.



It seems Notification Channel issue.

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

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.

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) {
//then your code to create channel
NotificationChannel channel = new NotificationChannel(channelId, name, importance);