Is there a method that can be used to mute the global sound from an application button?
相关问题
- How can I create this custom Bottom Navigation on
- Can we recover audio from MFCC coefficients?
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Is there a way to play audio on a mobile browser w
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
You can use setRingerMode() method to do this
mute & vibrate RINGER_MODE_VIBRATE flag
unmute: RINGER_MODE_NORMAL
The answer provided seems to be deprecated from android M (API 23) so this is provides an alternative solution
hope this helps...
There are four kinds of sound setting in Android:
First, create an object of the
AudioManager
class:If you want to set the volume, use these:
For notification
For alarm
For music
For ringtone
They make it more complicated than it has to be. You can just use
AudioManager.setStreamMute()
. Feel free to use the code below.Technically there is no such thing as a global volume. Bhargav's answer should put you on the right track. There are many different "streams" that can be controlled by the AudioManager class, namely Music, Ringer, In-Call, Alarm, Notification, System and DMTF. You have to set the volume for all of these individual streams to 0, which is an incredibly simple process as Bhargav as shown.
Just create an Audiomanager object:-
And then use it to change the volume for all the streams:-
Instead of typing AudioManager.Stream, type "AudioManager." and press Ctrl+Space Bar to see all of the different streams you can use. Check the documentation for the many different types of flags that can add a sound or a vibration or bring up the volume UI when the volume is changed.
Each stream may have a different maximum volume so be sure to use getMaxStreamVolume to get the maximum values and set the volume accordingly in case you are using a single value to edit all the streams. So if the user wants to set global volume to 50%, get the maximum volume for each stream, multiply them by 0.5, and set it to the corresponding streams.