android - 在 android 中为通知设置振动、灯光或声音的组合

标签 android android-notifications

我想为用户提供选择 Lights、Sounds 或 Vibration 或这三者的组合的选项,以在 Notification 上发出警报。

在 android 文档中,我看到有一个 DEFAULT_ALL 选项,其中将使用所有三种警报方法。

否则有一个选项可以选择其中任何一个(DEFAULT_LIGHTSDEFAULT_VIBRATEDEFAULT_SOUND)。

有什么方法可以组合SOUNDVIBRATION但没有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 11NotificationCompat.Builder API 1提供了几种不同的方法来设置这些类型的警报。

  • 设置灯光(...)
  • 设置声音(...)
  • 设置振动(...)

The value should be one or more of the following fields combined with bitwise-or: DEFAULT_SOUND, DEFAULT_VIBRATE, DEFAULT_LIGHTS.

未经测试,但我相信如果你想要SOUNDVIBRATIONLIGHTS,你会做这样的事情:

setDefaults(DEFAULT_SOUND | DEFAULT_VIBRATE | DEFAULT_LIGHTS);

关于android - 在 android 中为通知设置振动、灯光或声音的组合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12006724/

相关文章:

android - Jetpack Compose 在外部单击时折叠 Bottom Sheet

android - 即使应用程序在前台,如何让 FCM 显示通知?

android - 来自通知的 Activity 中收到错误的 Intent (在服务中)

java - 为通知创建 PendingIntent 而不指定 Activity

android - 如何从通知导航到 fragment ?安卓 Kotlin

java - 无法将 ImageJ 集成到 Android 应用程序中

java - 如何从Android使用谷歌应用程序引擎查询实体?

android - 通过 Internet 调试 android 设备

android - Jquery 移动样式图像

android - 将 Android 通知从 FLAG_ONGOING_EVENT 切换为可取消