androidpush-notificationreact-nativereact-native-push-notification

Unable to dismiss notification from notification bar in react native push notification (Android)


I'm creating a remainder application in which I couldn't able to dismiss the notification from the notification area, I've tried many methods to resolve this but still, nothing helps, PushNotification.clearLocalNotification(parseInt(notification.id, 10)); tried this to dismiss notification (not removing/cancelling). also tried similar solution like PushNotification.cancelLocalNotifications({ id: `${parseInt(notification.id, 10)}` });. but still, nothing helps. I tried logging the node package, I could see the logging inside the clear notification java function/cancel function, still not dismissing from the notification area

Edit: I want to dismiss the notification on the action (button) press.


Solution

  • Use autoCancel: true to dismiss notification on notification tap

    export const LocalNotification = () => {
      PushNotification.localNotification({
        autoCancel: true,
        bigText:
          'This is local notification demo in React Native app. Only shown, when expanded.',
        subText: 'Local Notification Demo',
        title: 'Local Notification Title',
        message: 'Expand me to see more',
        vibrate: true,
        vibration: 300,
        playSound: true,
        soundName: 'default',
        actions: '["Yes", "No"]'
      })
    }