getExpoPushTokenAsync not responding on Android testing device

#1

Hi,

I know there have been a few similar requests regarding “standalone” devices out there, but this is about a (still) testing device in connection with the Expo XDE.

In short:

  • I am trying to get the Push Notification token using getExpoPushTokenAsync
  • this is working perfectly for iphones, but not for android phones
  • it used to work for both iphone and android about 2 months ago

Code:
token = await Notifications.getExpoPushTokenAsync();
–> return token for iphone, but nothing happens on Android (not even any following console.log)

just before:
const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS);
–> returns “granted”

I am using:
“expo”: “^30.0.1”,
“react”: “16.3.1”,
“react-native”: “https://github.com/expo/react-native/archive/sdk-30.0.0.tar.gz”,

I am aware of the following links and adices:


https://docs.expo.io/versions/v26.0.0/guides/using-fcm

But when trying to create a FCM project for my app I have to add the package name(format: com.company.name) and add the “google-services.json” into my root directory, which is not really possible as the app is stil in development mode and not standalone… I don’t have a package name in that format yet.

Does anybody has experienced this and found a solution to it?

Code snippet and output:

// if no existing permission ask user for permission
   console.log("status: -" + status + '-');
    if (status !== '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;
    }

    // If no permission, exit ...
    if (finalStatus !== 'granted') {
      return;
    }

    // Get the token that uniquely identifies this device
    console.log("BEFORE TOKEN....");
    let token = await Notifications.getExpoPushTokenAsync();
    console.log("TOKEN: " + token);

Output Android:

status: -granted-
TOKEN BEFORE....

Output iPhone:

status: -granted-
TOKEN BEFORE....
TOKEN: ExponentPushToken[Xxxxx_Xxxxxxxxxxxxxx]

Thanks so much for help

#2

Hey @admino - if you’re only experiencing this in the Expo client app (not your standalone app) could you try updating to the latest version, 2.9.1, and see if the issue has been resolved? It may take a little while to propagate out to your device, so if you don’t see the new version in the Play Store yet, give it a few hours or so.

#3

@esamelson We are unable to get token both in Testing as well as Standalone App. I have tried all the ways. Unfortunately we are getting the Token.
I have tested using SDK 30 and SDK 31. But still there is an issue

#4

Thanks sooooo much Esamelson!!!

This was indeed the solution! … and because my storage is quite full, the apps didn’t update automatically this time …
Thanks again!

#5

I had the same issue and I just downloaded the latest version released on the 5th of November but instead of not getting a response, now I am getting this message:
[Error: Couldn’t get GCM token for device]

The app works fine on iOS (11.0.2) and I receive the token but it was working even before the update. Do you have any idea what could be the problem? I have asked also here https://stackoverflow.com/questions/53199472/can-not-get-expo-push-token-on-android

#6

Hey peepneeapp,

which Expo version do you have on your android phone? This is the one that I had to update to 2.9.1 for it to work.
Not sure now, your issue seems to be slightly different though, but just make sure first that the version on your phone is up to date.

I personally have now the issue that - even though the token is created and the push notification receives an “ok” feedback from Expo, it is only rarely pushed to android phones… iphones are fine… If anyone could give me a hint there?

#7

Hi all,

so, I have done a whole series of tests.
Please note that my app is still in test mode, I have to view it via my Expo app on the phones.

  • I have created a PHP functionality sending push notifications to any user of the app that has accepted (i.e. all the tokens that I received and stored).

  • for androids, a channel is created on the phones (this is now a new request from android)
    Expo.Notifications.createChannelAndroidAsync
    For this, the android phone has to enter the app at least once before testing notifications…

This is what happens when notifications are sent:

  • Every iPhone gets the notification
  • Androids only get notification if phone is NOT in sleeping mode (but this is not absolutely consistent)… from then on, it even receives the notification SOMETIMES when phone is in sleeping mode… (but not always)

This is very confusing, I admit.
It seems definitely to help for Androids when the App is open (in background or not) and the phone not in sleeping mode…

I will have to test the situation with ejected apps and connection to FCM (see link at beginning of this Topic)

closed #8

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