Expo notifications still displaying even after setNotificationHandler return false for shouldShowAlert on Android

Please provide the following:

  1. SDK Version: 38.0.3
  2. Platforms: Android

In my code, I am using React’s useEffect hook to modify Notification.setNotificationHandler to return the NotificationBehaviour according to the current chat room id. However, the Android device still displays the notification when messages are received when viewing the chat room. On iOS, there is no such issue and notifications are not displayed when messages from the chat room are received while viewing the chat room. The code looks something like this:

useEffect(() => {

    Notifications.setNotificationHandler({
      handleNotification: async (notification) => {
        let body;
        if (Platform.OS === 'android') {
          body = (notification.request.content.data as AndroidNotificationData)
        } else if (Platform.OS === 'ios') {
          body = (notification.request.content.data as IOSNotificationData).body
        }

        if (body && body.id.toString() === group.id.toString()) {
          console.log("Do not show")
          return {
            shouldShowAlert: false,
            shouldPlaySound: false,
            shouldSetBadge: false,
            priority: Notifications.AndroidNotificationPriority.MIN
          }
        }
        return {
          shouldShowAlert: true,
          shouldPlaySound: false,
          shouldSetBadge: false,
          priority: Notifications.AndroidNotificationPriority.MAX
        }
      }
    })

    return () => {
      console.log("Unmounting")
      Notifications.setNotificationHandler({
        handleNotification: async () => ({
          shouldShowAlert: true,
          shouldPlaySound: false,
          shouldSetBadge: false,
          priority: Notifications.AndroidNotificationPriority.MAX
        })
      })
    }
  }, [])

In both cases, the “Do not show” is displayed on my console.

Im getting the exact same behavior. SDK 38. iOS behaves correctly. Android expo app does not.

just had a similar issue in iOS, we had previously set, iosDisplayInForeground: true in our app.json.

setting this to false, allowed Notifications.setNotificationHandler to do its thing.

Are you able to control whether the notification appears in the foreground with Android?

I still haven’t been able to resolve it. As far as I know, there is no iosDisplayInForeground type option for android.

Has anyone managed to solve this?

Just to clarify, I’m using the SKD38 with useNextNotificationsApi: true. Could that be the reason why?

Really curious that no one is experiencing this with android…

sorry I wasn’t more specific. yes, the notification still shows in android after this change.

Hey guys, just got fixed today after I reported it!