SDK 37 Permission.askAsync for standalone Android App bug?

Please provide the following:

  1. SDK Version: 37
  2. Platforms(Android/iOS/web/all): Standalone Android app (managed)

Hello everyone,
Got a strange one for ya. On initial load of my application, the user is presented with a push notification permission view, and if they click accept, this function is triggered

    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') {
      return Alert.alert(
        'Notifications are Disabled',
        "Would you like to be navigated to your phone's settings to update this permission?",
        [
          // Stop here if the user did not grant permissions
          {
            text: 'No Thanks',
            onPress: () => navigation.navigate(RouteNames.HomeScreen),
            style: 'cancel',
          },

          // Navigation user to app's settings screen to set permissions there
          {
            text: 'OK',
            onPress: () => {
              Linking.openSettings()
              navigation.navigate(RouteNames.HomeScreen)
            },
          },
        ],
        { cancelable: false }
      )
    }
    // Get the token that identifies this device
    const PushToken = await Notifications.getExpoPushTokenAsync()
    const UserEmail = await AsyncStorage.getItem('email')

    if (Platform.OS === 'android') {
      Notifications.createChannelAndroidAsync('default', {
        name: 'default',
        sound: true,
        priority: 'max',
        vibrate: [0, 250, 250, 250],
      })
    }

    // POST the token to your backend server from where you can retrieve it to send push notifications.
    return registerPushToken({
      UserEmail,
      PushToken,
    }).then(() => navigation.navigate(RouteNames.HomeScreen))
  }

If everything goes accordingly, the user will be pushed to the home screen and, if they accept, the BE will receive the expo token that is generated. This works flawlessly in iOS, both standalone and locally (expo server spun up and using a real iOS device over network) and for android locally.

The issue is for standalone android users. Nothing happens if the user clicks the “OK” button. They are just stuck there. I really can’t log anything out to figure out where, in the function, it’s hung up on since it’s a standalone app on an android device. The BE also does not receive the expo token so it appears that its hung up on the askAsync/getAsync. Any help here??

  • if it helps, this app was not setup with firebase correctly, so I know it will not be receive notifications, but it should still be able to get/ask for notifications permissions and get an expo token without a firebase set up, right??

Hey @jacobjohn90,

You’ll need to configure FCM in order to generate the underlying Device Token which allows the Notifications module to generate an Expo Push Token. It will error out if not configured properly. Additionally, you may want to wrap the token generation code in a try/catch block so that your app can continue to function and navigate the user to your HomeScreen.

Cheers,
Adam

Thank you so much for that response @adamjnav. Had no idea that the FCM configuration affected the Notifications module to generate the Expo Push Token! Will be implementing this now and I’ll come back and update the thread!

worked like a charm! thanks!

1 Like

Glad to hear it!