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:
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.
(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.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With