Is there a method that can be used to mute the global sound from an application button?
If you have an Android phone, you can mute your phone from the call screen. Your call screen has different buttons including a mute button (circled below). It is a microphone with a slash line through it. Please click on this button to mute and unmute your hone.
So if you'd like to get rid of this toast message, open App Volume Control and tap the settings icon at the top of the screen. From here, simply disable the "Notify with a notification" option, and from now on, your volume levels will change automatically and silently when you open any of the apps you configured.
They make it more complicated than it has to be. You can just use AudioManager.setStreamMute()
. Feel free to use the code below.
//mute audio AudioManager amanager=(AudioManager)getSystemService(Context.AUDIO_SERVICE); amanager.setStreamMute(AudioManager.STREAM_NOTIFICATION, true); amanager.setStreamMute(AudioManager.STREAM_ALARM, true); amanager.setStreamMute(AudioManager.STREAM_MUSIC, true); amanager.setStreamMute(AudioManager.STREAM_RING, true); amanager.setStreamMute(AudioManager.STREAM_SYSTEM, true); //unmute audio AudioManager amanager=(AudioManager)getSystemService(Context.AUDIO_SERVICE); amanager.setStreamMute(AudioManager.STREAM_NOTIFICATION, false); amanager.setStreamMute(AudioManager.STREAM_ALARM, false); amanager.setStreamMute(AudioManager.STREAM_MUSIC, false); amanager.setStreamMute(AudioManager.STREAM_RING, false); amanager.setStreamMute(AudioManager.STREAM_SYSTEM, false);
The answer provided seems to be deprecated from android M (API 23) so this is provides an alternative solution
public void MuteAudio(){ AudioManager mAlramMAnager = (AudioManager) aActivity.getSystemService(aContext.AUDIO_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { mAlramMAnager.adjustStreamVolume(AudioManager.STREAM_NOTIFICATION, AudioManager.ADJUST_MUTE, 0); mAlramMAnager.adjustStreamVolume(AudioManager.STREAM_ALARM, AudioManager.ADJUST_MUTE, 0); mAlramMAnager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_MUTE, 0); mAlramMAnager.adjustStreamVolume(AudioManager.STREAM_RING, AudioManager.ADJUST_MUTE, 0); mAlramMAnager.adjustStreamVolume(AudioManager.STREAM_SYSTEM, AudioManager.ADJUST_MUTE, 0); } else { mAlramMAnager.setStreamMute(AudioManager.STREAM_NOTIFICATION, true); mAlramMAnager.setStreamMute(AudioManager.STREAM_ALARM, true); mAlramMAnager.setStreamMute(AudioManager.STREAM_MUSIC, true); mAlramMAnager.setStreamMute(AudioManager.STREAM_RING, true); mAlramMAnager.setStreamMute(AudioManager.STREAM_SYSTEM, true); } } public void UnMuteAudio(){ AudioManager mAlramMAnager = (AudioManager) aActivity.getSystemService(aContext.AUDIO_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { mAlramMAnager.adjustStreamVolume(AudioManager.STREAM_NOTIFICATION, AudioManager.ADJUST_UNMUTE, 0); mAlramMAnager.adjustStreamVolume(AudioManager.STREAM_ALARM, AudioManager.ADJUST_UNMUTE, 0); mAlramMAnager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_UNMUTE,0); mAlramMAnager.adjustStreamVolume(AudioManager.STREAM_RING, AudioManager.ADJUST_UNMUTE, 0); mAlramMAnager.adjustStreamVolume(AudioManager.STREAM_SYSTEM, AudioManager.ADJUST_UNMUTE, 0); } else { mAlramMAnager.setStreamMute(AudioManager.STREAM_NOTIFICATION, false); mAlramMAnager.setStreamMute(AudioManager.STREAM_ALARM, false); mAlramMAnager.setStreamMute(AudioManager.STREAM_MUSIC, false); mAlramMAnager.setStreamMute(AudioManager.STREAM_RING, false); mAlramMAnager.setStreamMute(AudioManager.STREAM_SYSTEM, false); } }
hope this helps...
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