Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable the Volume Toast

Tags:

android

volume

I'm trying to increase the volume using AudioManager.

But it showing Native Android Volume UI(Volume Seekbar) toast.I want to disable this. I know this can be possible in Activity using Key Event but i want to do it through service. How to disable the toast? Here is a screenshot of the toast:
enter image description here

like image 699
Satheesh Kumar Avatar asked Aug 28 '12 16:08

Satheesh Kumar


People also ask

How do I turn off volume control on Android?

Choose the “Short and long press” option. Open the drop-down list under “Key” and choose “VOLUME_DOWN.” Open the drop-down list under “Action” and select “Do nothing.” Tap the “OK.” That's it. If you want to enable both the volume buttons, delete both the actions you've created.

How do I lock media volume on Android?

(Menu names may vary based on Android version.) There you can set the default volume for many of the phone's functions, including ringtone, system alerts and media. To lock the levels, tap the three-dot More options menu on the screen and choose Media Volume Limiter.


1 Answers

The AudioManager-class offers the following methods to adjust the volume of certain streams:

  • adjustVolume(int, int)
  • adjustStreamVolume(int, int, int)
  • adjustSuggestedStreamVolume(int, int, int)
  • setStreamVolume(int, int, int)

All those methods take a flag-parameter as their last argument. The flag which is interesting for 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) but 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 works for me on Android 4.0.4 (Motorola Xoom) and Android 2.3.5 (HTC Desire HD).

like image 117
Lukas Knuth Avatar answered Sep 22 '22 23:09

Lukas Knuth