Using Nokia 7.2 (Android 11) I can't make push notification to show up for my app.
Preconditions:
- On iOS everything works (local/push notification)
- Android local notification works (both foreground/background)
- I am using an eas standalone development build (apk)
- In my android device settings, all notifications are enabled
- ExpoToken is set properly, no error
- Push ticket and receipt are sent without an error (see below)
- FCM server key is set properly
- push notifications from other apps are working properly for this device
Unfortunately I have no other android device to test push notification, is it possible to test on emulator? If yes, then it doesnt work there either, because i tried already. No errors.
Client side code:
useEffect(() => {
registerForPushNotificationsAsync().then((token) =>
setExpoPushToken(token)
);
notificationListener.current =
Notifications.addNotificationReceivedListener(setNotification(noti));
responseListener.current =
Notifications.addNotificationResponseReceivedListener((response) => {
setNotification(response.notification);
});
return () => {
notificationListener.current &&
Notifications.removeNotificationSubscription(
notificationListener.current
);
responseListener.current &&
Notifications.removeNotificationSubscription(responseListener.current);
};
}, [user]);
async function registerForPushNotificationsAsync() {
let token;
if (Platform.OS === "android") {
await Notifications.setNotificationChannelAsync("default", {
name: "default",
importance: Notifications.AndroidImportance.MAX,
vibrationPattern: [0, 250, 250, 250],
lightColor: "#FF231F7C",
});
}
if (Device.isDevice) {
const { status: existingStatus } =
await Notifications.getPermissionsAsync();
let finalStatus = existingStatus;
if (existingStatus !== "granted") {
const { status } = await Notifications.requestPermissionsAsync();
finalStatus = status;
}
if (finalStatus !== "granted") {
alert("Failed to get push token for push notification!");
return;
}
token = (await Notifications.getExpoPushTokenAsync()).data;
await user_ref(user.uid).update({
["push_token"]: token,
});
setToken(token);
} else {
alert("Must use physical device for Push Notifications");
}
return token;
}
It is basically the same as the documents says.
Then I send push notification manually to the right token:
curl -H "Content-Type: application/json" -X POST "https://exp.host/--/api/v2/push/send" -d '{
"to": "EXPOTOKEN",
"title":"hello",
"body": "world"
}'
Response is OK:
{"data":{"status":"ok","id":"xxx-xxx-xxx-xxx-xxx"}}%
Checking the receipt for the received id:
curl -H "Content-Type: application/json" -X POST "https://exp.host/--/api/v2/push/getReceipts" -d '{
"ids": [
"xxx-xxx-xxx-xxx-xxx"
]
}'
Response is OK:
{"data":{"xxx-xxx-xxx-xxx-xxx":{"status":"ok"}}}%
Here is a screenshot of my app notification settings:
Without any errors, how and where to start troubleshooting?