notifications listener doesn't work for Android

Hi,
1)Notifications listener doesn’t work for Android and works fine for IOS when added below code inside a function.

const backgroundSubscription = Notifications.addNotificationResponseReceivedListener(response=>{ });

const foregroundSubscription = Notifications.addNotificationReceivedListener(notification =>{})

2)Also listener doesn’t get trigger from useEffect for Android neither for iOS ,as mentioned in the docs.

Provide some update for this issue.

Hi, there’s not enough info here to help you. The example Snack from the docs uses both of these listeners, and they each work on iOS and Android on SDK 41 Notifications - Expo Documentation

@charliecruzan what info should we share? I’m having the same issue in an Expo Go app, working fine for iOS but in Android notification received callback is not firing, should we add any particular code for Android?

  1. Ive updated expo to SDK 41.
  2. Ive followed the tutorial for setting up push notifications
  3. Ive added received callback subscription to component initialization
useEffect(() => {
    BackHandler.addEventListener('hardwareBackPress', onBackButtonPressAndroid)

    notificationListener.current = Notifications.addNotificationReceivedListener(notification => {
      const message = JSON.stringify({
        code: 'refresh' 
      })
      Helper.handleInjectJavascript(webviewRef?.current, message)
    });

    responseListener.current = Notifications.addNotificationResponseReceivedListener(response => {
      // bypass
    });
    
     return () => {
      Notifications.removeNotificationSubscription(notificationListener.current);
      Notifications.removeNotificationSubscription(responseListener.current);
    };
  }, [])
  1. Ive added this to app.json file:
"useNextNotificationsApi": true,
"permissions": ["RECEIVE_BOOT_COMPLETED"]

But this is only firing in iOS device:

notificationListener.current = Notifications.addNotificationReceivedListener(notification => {
      const message = JSON.stringify({
        code: 'refresh' 
      })
      Helper.handleInjectJavascript(webviewRef?.current, message)
    });

Same problem here, it was working fine before I upgrade to SDK 41. It’s worth noting that it works normally on the standalone app, however.

I got the solution for this problem
Just add this line in app.json file and notification listener will work for android
“android”: {
“useNextNotificationsApi”: true
},

This really helped. Really appreciate the input there.

Q - is this anywhere in the expo docs? I tried looking but could not find it.

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