At least on Pixel phones, it's possible to mute the phone from settings. However, I didn't find any Android API to set the phone in this mode as you can see from the screenshot. If I use the AudioManager
using the setRingerMode
the phone is set into vibrate mode and/or the "Don't disturb" icon is shown. Does anyone know how to use this feature?
If you allowed that recently installed app to make system changes, there's a chance that that app is sending your phone into silent mode automatically. First, check for the sound control permissions of all the installed apps and Deny permission to whichever app has the access to it.
What Do They Do. The silent mode is the basic form among the three. It simply turns off all the notification sounds; be it incoming calls, messages, or app notifications, you won't hear any of them.
You can silence your phone with Do Not Disturb. This mode can mute sound, stop vibration, and block visual disturbances. You can pick what you block and what you allow.
Make sure you've declared following permission in AndroidManifest.xml
file.
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
EDIT 2
I've also tested it on Google Pixel 2 API 28 and it is working as expected.
As you can see there is no “Don't Disturb(DND)” button in the notification bar.
EDIT
audioManager.setStreamVolume(AudioManager.STREAM_RING, 0, 0)
will let you achieve the desired functionality without "do not disturb" icon.
Output
Original
AudioManger's method name setRingerMode(int ringerMode) allows you to set the mode you want.
Documentation:
Silent mode will mute the volume and will not vibrate. Vibrate mode will mute the volume and vibrate. Normal mode will be audible and may vibrate according to user settings.
This method has no effect if the device implements a fixed volume policy as indicated by isVolumeFixed().
From N onward, ringer mode adjustments that would toggle Do Not Disturb are not allowed unless the app has been granted Do Not Disturb Access. See NotificationManager#isNotificationPolicyAccessGranted().
/**
* Changes mobile profile to "Silent" or "Vibrate" or "Normal" mode
*
* @param context
* @param mode - "0 - Silent"
* - "1 - Vibrate"
* - "2 - Normal"
*/
public static void chooseProfile(Context context, int ringerMode) {
AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
if (ringerMode == 0)
audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
else if (ringerMode == 1)
audioManager.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
else if (ringerMode == 2)
audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
}
See also:
getRingerMode()
isVolumeFixed()
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