Search code examples
androidnotificationsandroid-serviceforeground-service

how to stop Foreground service notification 'noise' programmatically when invoking notification UI display


I don't know why, but for some reason, whenever I use the startForeground(...) or the notificationManagar.notify(...) command on android oreo and above there is a notification sound that lasts almost 1 second.

This wouldn't be a problem, if it only sounded the first time, but, it sounds everytime whenever I update the notification UI (which is again done by doing the notificationManager.notify.

Is there some way I can disable this sound while my app is active?(since, I don't know why the system would need it, but, there must be something the system has designed it for)


Solution

  • As notification channels are a must for Oreo+ APIs, then this is most probably related to the channel.

    I think you can stop this sound by using NotificationManager.IMPORTANCE_LOW while creating the Foreground service notification channel.

    NotificationChannel serviceChannel = new NotificationChannel(
                    CHANNEL_ID,
                    CHANNEL_NAME,
                    NotificationManager.IMPORTANCE_LOW // <<<<<
            );
    
    NotificationManager manager = getSystemService(NotificationManager.class);
    manager.createNotificationChannel(serviceChannel);