evollu / react-native-fcm

react native module for firebase cloud messaging and local notification
MIT License
1.73k stars 681 forks source link

Clear all notifications in the android notification tray #1119

Open danmdinu opened 5 years ago

danmdinu commented 5 years ago

I'm sending multiple notifications to my app. What I want to achieve is whenever a user clicks one notification then all notifications in the notification tray disspear.

I've tried adding

notification.android.setAutoCancel(true)

which does the trick for only one notification (the one which is being clicked)

I've also tried:

firebase.notifications().removeAllDeliveredNotifications()

which doesn't have any effect.

How can I achieve this?

Here's my full code:

   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();
}`
danmdinu commented 4 years ago

any idea anyone? ^^ thanks

kunal-oxl commented 2 years ago

@danmdinu were you able to solve this?