firebase - 禁用本地通知声音
问题描述
我正在尝试使用 react-native-firebase 显示没有声音的本地通知,这可能吗?
我尝试过使用 AndroidNotification 类,但找不到这样做的方法。
const notification = new firebase.notifications.Notification()
.setNotificationId("notificationId")
.setTitle("Title")
.setBody("Text")
.android.setBigText("Big Text")
.android.setColor("#f04e29")
.android.setAutoCancel(true)
.android.setOnlyAlertOnce(true)
.android.setChannelId("channel")
.android.setLargeIcon("ic_launcher")
.android.setSmallIcon("ic_notification");
firebase.notifications().displayNotification(notification);
我希望通知显示时没有任何噪音。
解决方案
根据我自己的经验,必须考虑两点:
- 无需调用 setSound 方法或不设置声音属性
在为 Android API 级别 >=26 进行开发时,作为 Channel 方法的第三个参数传递的 Android 重要性必须设置为 Low、Min 或 None。否则无论如何都会播放默认声音。所以一个创建你的频道的例子(例如在你的 App.tsx 的 componentDidMount 中):
const channel = new firebase.notifications.Android.Channel("testNotification", "Test Notification", firebase.notifications.Android.Importance.Low) firebase.notifications().android.createChannel(channel);
然后显示一个不显眼的通知:
const notification = new firebase.notifications.Notification()
.setTitle("My notification title")
.setBody("My notification body");
notification.android.setChannelId("testNotification");
firebase.notifications().displayNotification(notification);
推荐阅读
- java - MPEG 2 TS ISOMEDIA 投诉
- android - 63:错误:XML 文档结构必须在同一实体内开始和结束
- clojure - Clojure Spec 中有没有办法断言某事必须是谓词
- reactjs - axios请求错误404:找不到目标文件
- prolog - 对更新知识库时如何使用 \= 感到困惑
- jquery - 模态 JS 错误 - 对象不支持属性或方法“模态”
- java - 按名称自动装配弹簧
- java - 将两个哈希图与相等的键进行比较并检查更高的值
- firebase - Firebase Auth - 自定义声明的用户列表
- python - 如何将变量添加到 Python 中的 JSON 列表?