I am using Galaxy Nexus with Android 4.0, I set the silent mode to vibrate in Settings. I use NotificationManager.notify to send the Notification. I don't set Notification.vibrate, I even use myNotification.defaults &= ~Notification.DEFAULT_VIBRATE to disable the vibration. But it still vibrate after calling NotifcationManager.notify. Could anyone tell me how to turn off the vibration of a Notification in vibrate mode?
Asked
Active
Viewed 7,121 times
5 Answers
4
use the following code:
notification.defaults = Notification.DEFAULT_LIGHTS;
//or
notification.defaults = Notification.DEFAULT_SOUND;

Hai Bo Wang
- 632
- 3
- 6
2
To disable Vibration when notification comes, I use this code.
notification.vibrate = new long[] { -1 };
And its working perfectly.

Bunny
- 576
- 4
- 19
1
To manage notification settings dynamically:
notification.defaults = Notification.DEFAULT_LIGHTS;
if(/*sound enabled*/)
notification.defaults |= Notification.DEFAULT_SOUND;
if(/*vibration enabled*/)
notification.defaults |= Notification.DEFAULT_VIBRATE;

Hartok
- 2,147
- 20
- 37
0
First store the value of your vibrate setting button in shared preference. and then place this code where your notification is received.
SharedPreferences preferences = context.getSharedPreferences("VIBRATE",
0);
boolean vibrate = preferences.getBoolean("vibrate", true);
if (vibrate) {
notification.defaults |= Notification.DEFAULT_VIBRATE;
}

Kishan Dhamat
- 3,746
- 2
- 26
- 36
0
It can also be done using the following adb command for specific package
adb shell
cmd appops set package_name VIBRATE ignore
The above command will disable all vibrations for package_name package.

nandal
- 2,544
- 1
- 18
- 23