Expo push notifications not working on Android standalone app

Please provide the following:

  1. SDK Version: 40.0.0
  2. Platforms(Android/iOS/web/all): Android

I’m working on an expo app and I’ve added expo push notifications and that’s working for iOS but not on android. The problem is caused by getExpoPushTokenAsync() because it doesn’t resolve.

I’m working with Expo version 40.0.0 and using the following code to get the notification token:

export async function registerForPushNotificationsAsync(t) {
      if (Constants.isDevice) {
        const { status: existingStatus } = await Permissions.getAsync(Permissions.NOTIFICATIONS);
        let finalStatus = existingStatus;
        if (existingStatus !== 'granted') {
          const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS);
          finalStatus = status;
        }
        if (finalStatus !== 'granted') {
          alert(t('no_access_push_notifications'));
          return;
        }
        const token = await Notifications.getExpoPushTokenAsync();
        return token;
    
        // this.setState({ expoPushToken: token });
      } else {
        console.log("No physical device");
      }
    
      if (Platform.OS === 'android') {
        Notifications.setNotificationChannelAsync('default', {
          name: 'default',
          importance: Notifications.AndroidImportance.MAX,
          vibrationPattern: [0, 250, 250, 250],
          lightColor: '#FF231F7C',
        });
      }
    };

I’ve created a new project in Firebase according to the Expo docs for Android and copied the google-services.json to the root of my app and linked it in my app.json

 {
      "project_info": {
        "project_number": "xxxxxxxxx",
        "project_id": "xxxxxxxxx",
        "storage_bucket": "xxxxxxxxx"
      },
      "client": [
        {
          "client_info": {
            "mobilesdk_app_id": "xxxxxxxxx",
            "android_client_info": {
              "package_name": "xxxxxxxxx"
            }
          },
          "oauth_client": [
            {
              "client_id": "xxxxxxxxx",
              "client_type": 3
            }
          ],
          "api_key": [
            {
              "current_key": "xxxxxxxxx"
            }
          ],
          "services": {
            "appinvite_service": {
              "other_platform_oauth_client": [
                {
                  "client_id": "xxxxxxxxx",
                  "client_type": 3
                }
              ]
            }
          }
        }
      ],
      "configuration_version": "1"
    }

My app.json contains the following code:

 "android": {
          "package": "xxxxx",
          "versionCode": 4050,
          "googleServicesFile": "./google-services.json",
          "config": {
            "googleSignIn": {
              "apiKey": "xxxxx"
            }
          },
          "useNextNotificationsApi": true
        },

Any thoughts on this?

I’m testing on an android device btw

I am having the same problem, did you get something figure out?

Thank You for posting this. Same issue here.

Yo, I changed my code to legacy option and it worked. Hope it works for you too
const [expoPushToken, setExpoPushToken] = useState(’’);
const [notification, setNotification] = useState(false);
const notificationListener = useRef();
const responseListener = useRef();

    useEffect(() => {
      registerForPushNotificationsAsync().then(token => setUserToken(token));

      notificationListener.current = Notifications.addNotificationReceivedListener(notification => {
        setNotification(notification);
      });

      responseListener.current = Notifications.addNotificationResponseReceivedListener(response => {
        console.log(response);
      });

      return () => {
        Notifications.removeNotificationSubscription(notificationListener);
        Notifications.removeNotificationSubscription(responseListener);
      };
    }, []);

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