26

How do you allow the device to vibrate or make a sound when a notification is launched.

Ive heard of the FLAGS. But how would i use them for Sound and Vibration?

yoshi24
  • 3,147
  • 8
  • 45
  • 62

2 Answers2

74

Edit In Android v4 support library, there is NotificationCompat.Builder and the method setSound which will work if using that class instead. However, the info below will still work.

Notification notif ... //create your notification

notif.defaults |= Notification.DEFAULT_SOUND;
notif.defaults |= Notification.DEFAULT_VIBRATE;

That adds sound and vibrate.

Always remember to check the docs. They have a LOT of answers, such as this one:

http://developer.android.com/guide/topics/ui/notifiers/notifications.html

That has the info I posted above as well as info on how to use a custom sound or vibrate and also the entire process of creating a notification.

EDIT: Don't forget to include the Vibrate permission in your manifest.

Reed
  • 14,703
  • 8
  • 66
  • 110
  • How to disable this notification sound? I need to mute the default sound. How can I achieve this? – Karthick Oct 03 '13 at 04:59
  • I believe you can just not include the line `notif.defaults |= Notification.DEFAULT_SOUND;` – Reed Oct 03 '13 at 16:04
20
Notification notification // new notification object.
notification.defaults = Notification.DEFAULT_ALL;

Shows all the default notifications. (sound, vibration, led)

Gautham
  • 3,418
  • 3
  • 30
  • 41