How to disable sound in notification (Notification in Android O or above)

Viewed 6690

My app requirement is to update the a media style notification upon player state change. Work perfectly before, fires and shows a new media type notification with the mediaSession without sound or vibration.

Problem now: In building a notification channel per Android O requirement, I use the following code to create the notification channel. Then the annoying problem is, every time the media session changes, each notification updates, in Android O now plays a notification sound.

I would like to disable the sound for each new notification, if I don't set a sound, the default sound fires, passing in null in both field doesn't work.

 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationChannel notificationChannel = new NotificationChannel(
                NOTIFICATION_CHANNEL_ID,
                "SimpleBakingApp Media Notification",
                NotificationManager.IMPORTANCE_LOW
        );

        // Configure the notification channel.
        notificationChannel.setDescription("Channel description");
        notificationChannel.setSound(null,null); // <-- Is there a way to disable sound? null doesn't work
        notificationChannel.enableLights(true);
        notificationChannel.setLightColor(Color.RED);
        notificationChannel.enableVibration(false);
        mNotificationManager.createNotificationChannel(notificationChannel);
    }

Extra info, may be relevent

my showNotification() (The method that builds the notification) fires upon player state changes in the Player.EventListener callback, I'm using ExoPlayer v2.

1 Answers
Related