Use Case

I recently built a setting page for my application. I need to control the volume and brightness within my application. The function works fine, but I have a problem: when I slide the bar to adjust the value, the system volume UI also appears on the right side on the device screen.

In this article, I’ll share how to control the volume value without any system notification.

AudioManager

The AudioManager provides access to volume and ringer mode control. It offers the following methods to adjust the volume of certain streams:

All those methods take a flag-parameter as their last argument. The flag that is relevant to you is the FLAG_SHOW_UI, which:

Show a toast containing the current volume.

So, to get rid of the Toast, don’t supply this flag (or the int-value 1); instead, supply all your other flags (if needed) or just 0:

AudioManager manager = (AudioManager)this.getSystemService(Context.AUDIO_SERVICE);
manager.adjustVolume(AudioManager.ADJUST_RAISE, 0);

The above code snippet was tested and works for me on Android 9 and 10. I believe it also works on higher versions.

References