4

According to the document,

getRingerMode() returns the current ringtone mode, one of RINGER_MODE_NORMAL, RINGER_MODE_SILENT, or RINGER_MODE_VIBRATE.

But there should be 4 modes, right?

Sound ON, Vibrate OFF: How can I know that the setting is this one?
Sound ON, Vibrate ON: RINGER_MODE_NORMAL
Sound OFF, Vibrate OFF: RINGER_MODE_SILENT
Sound OFF, Vibrate ON: RINGER_MODE_VIBRATE

Please help me out. Thank you.

enter image description here

iForests
  • 6,757
  • 10
  • 42
  • 75

2 Answers2

2

You can set the ringer method to RINGER_MODER_NORMAL (Sound and vibrate on) and separately set the vibrate setting to VIBRATE_SETTING_OFF(turn off vibrate completely) OR VIBRATE_SETTING_ONLY_SILENT.(Vibrate only if the mode is silent) as below:

To turn off ringtone vibrations:

setVibrateSetting (AudioManager.VIBRATE_TYPE_RINGER,AudioManager.VIBRATE_SETTING_OFF)

To turn off notification vibrations:

setVibrateSetting (AudioManager.VIBRATE_TYPE_NOTIFICATION,AudioManager.VIBRATE_SETTING_OFF)

UPDATE:To get the status of the current audio mode by

   if(getRingerMode ()==AudioManager.RINGER_MODE_NORMAL)
    {    if((getVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER))==AudioManager.AudioManager.VIBRATE_SETTING_OFF){    
        Log.d("Ringer Mode is":"ring with no vibraion")
        }
    else{
    Log.d("Ringer Mode is":"ring with vibraion")
    }

    else if(getRingerMode ()==AudioManager.RINGER_MODE_SILENT){

if((getVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER))==AudioManager.AudioManager.VIBRATE_SETTING_OFF){    
        Log.d("Ringer Mode is":"Silent with no vibraion")
        }
    else{
    Log.d("Ringer Mode is":"Silent with vibraion")
    }
    }
else{
 Log.d("Ringer Mode is":"Silent with vibraion")

}

In the Docs it is said that it RINGER_MODE_SILENT mode will override the vibrate setting.

PS: According to DOC get/setVibrateSetting()**method was **deprecated in API level 16. Note: I havent Tested the code.

  • I am not going to turn it off. Just need to know the system setting. – iForests Mar 11 '15 at 09:47
  • You can use the combitaion of getRingerMode() and getVirateSetting() to get the effect you desire. – Vigneshwaran Murugesan Mar 11 '15 at 10:04
  • 1
    But getVirateSetting() is deprecated... "This method was deprecated in API level 16. Applications should maintain their own vibrate policy based on current ringer mode that can be queried via getRingerMode()." – iForests Mar 11 '15 at 10:06
  • Though the marked as deprecated the method is till availble,If you fear about portability I have just checked the source of lollipop the method is still available https://github.com/android/platform_frameworks_base/blob/lollipop-release/media/java/android/media/AudioManager.java – Vigneshwaran Murugesan Mar 11 '15 at 10:16
  • Will deprecated functions ever be removed? Is there any worry about future-proofing? – Kyle Sweet Aug 15 '16 at 21:18
0
if (Settings.System.getInt(context.getContentResolver(), "vibrate_when_ringing", 0) == 1)
{    
    return true;
}
else if (Settings.System.getInt(context.getContentResolver(), "vibrate_when_ringing", 0) == 0)
{
    return false;
}

I have try, useful

slfan
  • 8,950
  • 115
  • 65
  • 78