How to use notification with sound and vibration?

China☆狼群 提交于 2019-12-18 10:50:46

问题


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?


回答1:


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.




回答2:


Notification notification // new notification object.
notification.defaults = Notification.DEFAULT_ALL;

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



来源:https://stackoverflow.com/questions/7238243/how-to-use-notification-with-sound-and-vibration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!