如何使用的通知声音和振动? [英] How to use notification with sound and vibration?

查看:147
本文介绍了如何使用的通知声音和振动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你如何让设备振动或发出声音时,通知将启动。

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?

推荐答案

修改在Android的V4支持库,有<一个href="http://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html"><$c$c>NotificationCompat.Builder该方法 setSound 如果使用类,而不是将工作。但是,下面的信息仍然有效。

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;

这增加了声音和振动。

永远记得检查文档。他们回答,像这样的很多:

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

<一个href="http://developer.android.com/guide/topics/ui/notifiers/notifications.html">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.

编辑:不要忘了包括振动允许在你的清单。

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

这篇关于如何使用的通知声音和振动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆