通知 - 清除 android 通知栏中的所有通知
Notifications - Clear all notifications in the android notification tray
-
android-notifications
-
react-native
-
firebase-cloud-messaging
-
firebase-notifications
-
react-native-firebase
我正在向我的应用程序发送多个通知。我想要实现的是,每当用户单击一个通知时,通知托盘中的所有通知都会消失。
我试过添加
notification.android.setAutoCancel(true)
这只对一个通知(被点击的通知)有效
我也试过:
firebase.notifications().removeAllDeliveredNotifications()
没有任何效果。
我怎样才能做到这一点?
这是我的完整代码:
componentDidMount() {
firebase.notifications().removeAllDeliveredNotifications()
this.notificationDisplayedListener = firebase.notifications().onNotificationDisplayed((notification) => {
});
this.notificationListener = firebase.notifications().onNotification(async (notification) => {
// Process your notification as required
notification.android.setAutoCancel(true)
firebase.notifications().removeAllDeliveredNotifications()
}
async componentWillMount() {
this.notificationDisplayedListener = firebase.notifications().onNotificationDisplayed((notification) => {
});
this.notificationListener = firebase.notifications().onNotification((notification) => {
});
this.notificationDisplayedListener();
this.notificationListener();
}
尝试移动删除通知的代码
(removeAllDeliveredNotifications()
) 从 onNotification
个听众到 onNotificationOpened
个听众。当您尝试删除到达时的通知时,可能存在竞争条件。
还因为您想在用户点击一个通知时清除通知。
PS。将通知侦听器保留在 componentDidMount
或 componentWillMount
中,而不是两者。
android-notifications
react-native
firebase-cloud-messaging
firebase-notifications
react-native-firebase
我正在向我的应用程序发送多个通知。我想要实现的是,每当用户单击一个通知时,通知托盘中的所有通知都会消失。
我试过添加
notification.android.setAutoCancel(true)
这只对一个通知(被点击的通知)有效
我也试过:
firebase.notifications().removeAllDeliveredNotifications()
没有任何效果。
我怎样才能做到这一点?
这是我的完整代码:
componentDidMount() {
firebase.notifications().removeAllDeliveredNotifications()
this.notificationDisplayedListener = firebase.notifications().onNotificationDisplayed((notification) => {
});
this.notificationListener = firebase.notifications().onNotification(async (notification) => {
// Process your notification as required
notification.android.setAutoCancel(true)
firebase.notifications().removeAllDeliveredNotifications()
}
async componentWillMount() {
this.notificationDisplayedListener = firebase.notifications().onNotificationDisplayed((notification) => {
});
this.notificationListener = firebase.notifications().onNotification((notification) => {
});
this.notificationDisplayedListener();
this.notificationListener();
}
尝试移动删除通知的代码
(removeAllDeliveredNotifications()
) 从 onNotification
个听众到 onNotificationOpened
个听众。当您尝试删除到达时的通知时,可能存在竞争条件。
还因为您想在用户点击一个通知时清除通知。
PS。将通知侦听器保留在 componentDidMount
或 componentWillMount
中,而不是两者。