Question

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?

Was it helpful?

Solution

use the following code:

notification.defaults = Notification.DEFAULT_LIGHTS;
//or 
notification.defaults = Notification.DEFAULT_SOUND;

OTHER TIPS

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;

To disable Vibration when notification comes, I use this code.

notification.vibrate = new long[] { -1 };

And its working perfectly.

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;
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top