React-native-firebase: Notification doesn't disappear after clicking on it.

Created on 10 May 2018  路  8Comments  路  Source: invertase/react-native-firebase

Using the below code I'm creating notifications.

this.notificationListener = firebase.notifications().onNotification(notification => {
        console.log("OnNotification", notification)
        notification.setTitle("MyApp")
        notification.android.setPriority(firebase.notifications.Android.Priority.High)
        notification.android.setChannelId("test-channel")
        firebase.notifications().displayNotification(notification);
})

But the notification doesn't disappear even after clicking on it. The only way to clear notification is to swipe it.

Most helpful comment

Found the solution. Added this line:

notification.android.setAutoCancel(true);

All 8 comments

Found the solution. Added this line:

notification.android.setAutoCancel(true);

thanks it worked

notification.android.setAutoCancel(true);

can you I know where should I use this line.

@musadiq-jinbade when building the notification to display.

@musadiq-jinbade when building the notification to display.

this is my code if app is in foreground after clicking on notification, doesn't clear in notification center?

/*

* Triggered when a particular notification has been received in foreground

* */


this.notificationListener = firebase.notifications().onNotification((notification) => {

  const { title, body } = notification;


  console.log('onNotification:');






  const localNotification = new firebase.notifications.Notification({

    sound: 'sampleaudio',

    show_in_foreground: true,

  })



    .setSound('sampleaudio.wav')

    .setNotificationId(notification.notificationId)

    .setTitle(notification.title)

    .setBody(notification.body)

    .android.setChannelId('fcm_FirebaseNotifiction_default_channel') // e.g. the id you chose above

    .android.setLargeIcon('ic_launcher')


    .android.setPriority(firebase.notifications.Android.Priority.High);



  firebase.notifications()

    .displayNotification(localNotification)



    .catch(err => console.error(err));


});

@musadiq-jinbade when building the notification to display.

this is my code if app is in foreground after clicking on notification, doesn't clear in notification center?

/*

* Triggered when a particular notification has been received in foreground

* */


this.notificationListener = firebase.notifications().onNotification((notification) => {

  const { title, body } = notification;


  console.log('onNotification:');






  const localNotification = new firebase.notifications.Notification({

    sound: 'sampleaudio',

    show_in_foreground: true,

  })



    .setSound('sampleaudio.wav')

    .setNotificationId(notification.notificationId)

    .setTitle(notification.title)

    .setBody(notification.body)

    .android.setChannelId('fcm_FirebaseNotifiction_default_channel') // e.g. the id you chose above

    .android.setLargeIcon('ic_launcher')


    .android.setPriority(firebase.notifications.Android.Priority.High);



  firebase.notifications()

    .displayNotification(localNotification)



    .catch(err => console.error(err));


});

Add .android.setAutoCancel(true) below .android.setLargeIcon('ic_launcher') or anywhere below const localNotification

Thanks! @hrishiakhade for the update. let me check I will update on same

It happens only on "IOS" not in "Android"

Was this page helpful?
0 / 5 - 0 ratings