App not asking for Push permissions, Push fails after first message

Hi there,

I am using Expo Push Notification and it works well with the Expo app both in the Android emulator as well as on my device (LG Q6, Android 7.1.1). However, when I build the standalone Android app with…

exp build:android

… and install it on my device, I am not prompted for the push notification permission and the permission request comes back with “granted”. I also receive a proper Expo Push Token. As said, it works absolutely perfect when running from the Expo App.

	/* registers application to allow push notifications */
	static async registerPush(){
		var result = "";
		var pushGranted = true;

		let permissionResult = await Permissions.getAsync(Permissions.NOTIFICATIONS);
		if(permissionResult.status !== 'granted'){
			/* permission does not yet exist */
			alert("Please allow push messages.");

			let decisionResult = await Permissions.askAsync(Permissions.NOTIFICATIONS);
			if(decisionResult.status !== 'granted'){
				pushGranted = false;
			}
		}

  		if (pushGranted == true) {
  			result = await Notifications.getExpoPushTokenAsync();
  		}

  		return result;
	}

When I install the app on my Android 7.1.1 LG Q6 phone and fire up push notifications with the API using Postman, then the first request comes back ok, but I do not see any push notification (App is in foreground).

REQUEST:
{
	"to": "ExponentPushToken[XXXXXXXXXXX]",
	"title": "You has messages",
	"body": "Something new just arrived"
}

RESPONSE:
{
    "data": {
        "status": "ok"
    }
}

Any request I make to the API afterwards fails with “DeviceNotRegistered” error code, although I send it through exactly as with the Expo App and exactly as with the first try.

REQUEST:
{
	"to": "ExponentPushToken[XXXXXXXXXXX]",
	"title": "Another try",
	"body": "Second message arrived"
}

RESULT:
{
    "data": {
        "status": "error",
        "message": "SNS failed to send the notification (reason: EndpointDisabled, status code: 400).",
        "details": {
            "error": "DeviceNotRegistered",
            "sns": {
                "statusCode": 400,
                "reason": "EndpointDisabled",
                "__message": "Endpoint is disabled"
            }
        }
    }
}

I really tried several ways, spent quite some time here in the forum, but could not really find the root cause of my issue. Further I have no idea, why I am not being asked for permission by the standalone app.

Many thanks in advance for your help!

Jan

Problem resolved: Installed the app directly on the device by copying the APK file onto it and it did not work. I now uploaded the APK to Play Store for an internal test drive and the push notifications work perfectly!

1 Like

glad you got things working. i’m not sure why device registration didn’t work there though.

I’m having a similar problem to the one described. Although publishing the app in the Play Store has not resolved the issue for me. I haven’t touched any of my code related to notifications recently. This was working fine with Expo 27 based on the last build I did May 18. But after building and publishing the app today (June 5), the notification permission is no longer being asked for on Android and the I’m getting the “DeviceNotRegistered” error as a result. My iOS build from today works fine via the AppStore.

Any idea how to troubleshoot this? Could it be an issue with the Android build?

Quick update on this. I seem to have resolved the issue, but I had to modify the suggested code provided in the Expo documentation. Instead of the following:

  // only ask if permissions have not already been determined, because
  // iOS won't necessarily prompt the user a second time.
  if (existingStatus !== 'granted') {
    // Android remote notification permissions are granted during the app
    // install, so this will only ask on iOS
    const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS);
    finalStatus = status;
  }

I did the following instead:

        // only ask if permissions have not already been determined, because
        // iOS won't necessarily prompt the user a second time.
        if (existingStatus !== 'granted' || Platform.OS === 'android') {
          // Android remote notification permissions are granted during the app
          // install, so this will only ask on iOS
          const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS);
          finalStatus = status;
        }

So regardless of whether the permission has been granted or not on Android, I always call the Permissions.askAsync function. It seems like if the permission has already been granted it doesn’t do anything on Android anyway.

@ccheever Any thoughts on whether that’s reasonable or not? My guess is that maybe a bug that was supposed to be fixed in Expo 26 wasn’t totally fixed for Android. From the Expo 26 release notes:

No longer returns only status=granted when asking for notifications permissions on Android.

So I’m guessing Permissions.getAsync was always returning granted for Android whether or not the permission was actually granted yet.

1 Like

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