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”
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);
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.
@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
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]
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?
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)