Handle Push Notifications Android : Help needed

I am testing the push notifications on my android phone.I am using postman to send a test notification.
I am also trying to handle the incoming notification and present the notification myself.The listener gets hit and the title,body fields are not there in the notification object.Only data.

As a result there is an exception “Invariant Violation: Local notifications on Android require a title” .

However i seem to get the notification some how

So i am wondering ,in android can we handle presenting the notification in the code without having to have expo do it?I have a requirement to take the user to a specific screen in my app based on the property value in the data sent via the notification.I want to do that in the listener.But expo seems to present the notification anyway.

Any help would be appreciated

1 Like

Hey @venkat547,

You can dismiss the notification on Android by leveraging AppState from react-native and utilize data to determine an action like so:

handleNotification = notification => {
    let { origin, data } = notification;
    if (origin === "received" && this.state.appState === "active") {
      this.handleReceivedNotif(data);
      if (Platform.OS === "android") {
        Notifications.dismissNotificationAsync(notification.notificationId);
      }
    } else {
      this.handleSelectedNotif(data);
    }
  };

Cheers,

Adam

1 Like

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.