我想为用户提供选择 Lights、Sounds 或 Vibration 或这三者的组合的选项,以在 Notification
上发出警报。
在 android 文档中,我看到有一个 DEFAULT_ALL
选项,其中将使用所有三种警报方法。
否则有一个选项可以选择其中任何一个(DEFAULT_LIGHTS
、DEFAULT_VIBRATE
、DEFAULT_SOUND
)。
有什么方法可以组合SOUND
和VIBRATION
但没有LIGHTS
和其他组合吗?
编辑
Notification.Builder 的
(来自 prolink007 的回答)方法 setDefaults(int default)
说:
The value should be one or more of the following fields combined with bitwise-or: DEFAULT_SOUND, DEFAULT_VIBRATE, DEFAULT_LIGHTS.
应该如何使用?
最佳答案
Notification.Builder API 11或 NotificationCompat.Builder API 1提供了几种不同的方法来设置这些类型的警报。
- 设置灯光(...)
- 设置声音(...)
- 设置振动(...)
The value should be one or more of the following fields combined with bitwise-or: DEFAULT_SOUND, DEFAULT_VIBRATE, DEFAULT_LIGHTS.
未经测试,但我相信如果你想要SOUND
、VIBRATION
和LIGHTS
,你会做这样的事情:
setDefaults(DEFAULT_SOUND | DEFAULT_VIBRATE | DEFAULT_LIGHTS);
关于android - 在 android 中为通知设置振动、灯光或声音的组合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12006724/