2

This is not working for Lollipop.

To Enable vibration:

audio.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER,
            AudioManager.VIBRATE_SETTING_ON);
audio.setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION,
            AudioManager.VIBRATE_SETTING_ON);

To Disable vibration:

audio.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER,
            AudioManager.VIBRATE_SETTING_OFF);
audio.setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION,
            AudioManager.VIBRATE_SETTING_OFF);

This will work fantastically in Kitkat.

Marsh K
  • 151
  • 1
  • 2
  • 9
  • Documentation suggest to use getRingerMode(), but I don't know how to do that in practice: http://developer.android.com/reference/android/media/AudioManager.html#VIBRATE_SETTING_ON – pstrag Aug 17 '15 at 14:53
  • This constant was deprecated in **API level 16.** But still works fine in _Kitkat._ I want to implement this in _Lollipop._ – Marsh K Aug 17 '15 at 15:05

1 Answers1

0

You can control the vibration on Lollipop with this code:

Settings.System.putInt(getContentResolver(), "vibrate_when_ringing", vibrate?1:0);

Also you need to add this permission to your manifest file:

<uses-permission android:name="android.permission.WRITE_SETTINGS" />

Please note however, that the above code won't allow you to change the vibration while the phone rings. I guess the phone app reads this setting before the ringing starts, and uses it until the ringing stops.

Shumoapp
  • 1,489
  • 16
  • 15