Hey there, im following the given Doc: https://docs.expo.io/versions/latest/guides/push-notifications/ and try to get notifications to expo clients and native apps.
iOS is working fine:
Android 9 isnt working on both and push notification Tool isnt working too.
Here is my Code:
import { Notifications } from 'expo';
import * as Permissions from 'expo-permissions';
...
componentWillMount = async () => {
await this.registerForPushNotifications(userid);
if (Platform.OS === 'android') {
Notifications.createChannelAndroidAsync('reminders', {
name: 'Alarm',
sound: true,
priority: 'max',
vibrate: [0, 250, 250, 250],
});
}
if (Platform.OS === 'android' && !Constants.isDevice) {
this.setState({
errorMessage: 'Oops, this will not work on Sketch in an Android emulator. Try it on your device!',
});
} else {
this._getLocationAsync();
}
...
registerForPushNotifications = async(user) => {
const { status: existingStatus } = await Permissions.getAsync(
Permissions.NOTIFICATIONS
);
let finalStatus = existingStatus;
//iOS
if (existingStatus !== 'granted') {
const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS);
finalStatus = status;
}
// Stop here if the user did not grant permissions
if (finalStatus !== 'granted') {
return;
}
// Get the token that uniquely identifies this device
let token = await Notifications.getExpoPushTokenAsync();
this.notificationSubscription = Notifications.addListener(this.handleNotification);
return fetch(PUSH_ENDPOINT+user+'/'+token)
.then((response) => response.json())
.then((responseJson) => {
console.log(JSON.stringify(responseJson));
})
.catch((error) => {
console.error(error);
});
}
What happened. All Tokens are saved correctly in my Database.
Now, when im sending notifications via php only the iOS Notifications receive my Phone.
What i am missing to receive notifications on Standby devices?
php postdata:
$postData[] = array(
"to" => $appuser->getPushtoken(),
"title" => '🚨Einsatzalarm',
"sound" => "default",
"body" => 'FFFFFFFF',
"channelId" => "alarm", // android 8.0 later
"priority" => "high",
);