1

I want to disable vibrations for notifications but I am not able to make it work. I want to make the notification sound be heard, but the phone should not vibrate. Here is my code:

audioManager.setStreamVolume(AudioManager.STREAM_NOTIFICATION, 2, 0);
audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
audioManager.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_OFF);
audioManager.setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION, AudioManager.VIBRATE_SETTING_OFF);

but when I receive a message or other notification that uses default sound settings, the phone vibrates. Can someone tell me how to achieve my goal?

Fraser
  • 74,704
  • 20
  • 238
  • 215
Buda Gavril
  • 21,409
  • 40
  • 127
  • 196

3 Answers3

0

I think they are not stop because you are use "setDefaults(Notification.DEFAULT_ALL)" in notification code so if you need to stop vibration and sound remove this line , or if you need to use the default sound and stop vibration I think you must use setDefaults(Notification.DEFAULT_SOUND) etc ...

Oubaida AlQuraan
  • 1,706
  • 1
  • 18
  • 19
-1

I think, you should not be directly using AudioManager. Instead, use Notification APIs:

if (isVibrationEnabled) {
    notification.defaults |= Notification.DEFAULT_VIBRATE;
}
ozbek
  • 20,955
  • 5
  • 61
  • 84
  • does this works for notifications for other applications? I'm not making notifications, I just want to disable vibrations for all the notifications – Buda Gavril Oct 16 '13 at 05:09
  • You can't disable vibration for all apps notifications unless you set the device to silent mode (for that, use `audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);`). Although, there are apps which override the silent mode and use vibration (most of them follow user settings of course). – ozbek Oct 16 '13 at 05:18
  • so I want to change this settings for notificationd and I know that these settings will work only for applications that follow user's settings. But I want the user to hear notification sount, but disable vibrations, but that code does not works, and I don't know why – Buda Gavril Oct 16 '13 at 05:28
  • Probably, because _"`setVibrateSetting()` --- **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()."_ – ozbek Oct 16 '13 at 05:32
-1

You will have to remove Vibration code form Notification api :

    notification.defaults |= Notification.DEFAULT_VIBRATE;
Siddharth_Vyas
  • 9,972
  • 10
  • 39
  • 69