Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Silent phone without "don't disturb"

Tags:

android

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. enter image description here 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?

like image 881
greywolf82 Avatar asked Sep 07 '19 10:09

greywolf82


People also ask

Why is my phone automatically silent?

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 does silent on phone mean?

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.

Does Android have silent mode?

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.


1 Answers

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.

enter image description here

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

enter image description here

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()

like image 118
Rahul Khurana Avatar answered Oct 11 '22 04:10

Rahul Khurana