[expo-notifications][android] Empty notifications received by the users (which are meant to be silent) via FCM
See original GitHub issueSummary
Im using AppsFlyer in my app with the option to track the app uninstalls. AppsFlyer does this by sending a silent notification to the device in order to see if it’s still active.
However on Android the notifications which are meant to be silent appear as normal notifications – but with no text. Only an empty notification.
In AppsFlyer docs, they suggest adding this:
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
if(remoteMessage.getData().containsKey("af-uinstall-tracking")){
return;
} else {
// handleNotification(remoteMessage);
}
}
but I cannot see a way to do this cause expo-notifications
is adding its own notification handler.
Any idea how can I solve this?
Why is expo-notifications
not handling the silent notifications properly?
Managed or bare workflow? If you have ios/
or android/
directories in your project, the answer is bare!
bare
What platform(s) does this occur on?
Android
SDK Version (managed workflow only)
41.0.0
Environment
Expo CLI 4.7.3 environment info: System: OS: macOS 11.5 Shell: 3.2.57 - /bin/bash Binaries: Node: 12.16.1 - /usr/local/bin/node Yarn: 1.22.10 - /usr/local/bin/yarn npm: 7.17.0 - /usr/local/bin/npm Managers: CocoaPods: 1.10.1 - /usr/local/bin/pod SDKs: iOS SDK: Platforms: iOS 14.5, DriverKit 20.4, macOS 11.3, tvOS 14.5, watchOS 7.4 Android SDK: Android NDK: 22.1.7171670 IDEs: Android Studio: 4.2 AI-202.7660.26.42.7351085 Xcode: 12.5.1/12E507 - /usr/bin/xcodebuild npmPackages: expo: ^41.0.0 => 41.0.1 react: 16.13.1 => 16.13.1 react-dom: 16.13.1 => 16.13.1 react-native: 0.63.4 => 0.63.4 react-native-web: ~0.13.12 => 0.13.18 npmGlobalPackages: expo-cli: 4.7.3 Expo Workflow: bare
Reproducible demo or steps to reproduce from a blank project
Setting the simple app
First you’ll need to create a bare expo project. We are gonna test this for Android.
Using the expo-notifications
library we can get the device_token by calling const token = await Notifications.getDevicePushTokenAsync();
. Use a simple console.log("here's your token:", token.data)
to print the token on the console.
Build and deploy the app to a real Android device (via Android Studio or using yarn android
). Run it and get your_device_token from the console.
Sending the silent notification
Now, let’s go ahead and create a POST request that target the following URL:
https://fcm.googleapis.com/fcm/send
Next up, you also need to configure the POST request headers.
Content-Type: application/json
Authorization: key=[your_server_key]
For the Authorization header, replace [your_server_key]
with the actual server key that you can obtain from Firebase (Cloud Messaging). Please note that the key=
prefix must be included as part of the Authorization header.
The notification payload is a JSON formatted string that will be delivered alongside the silent push notification. Here’s a sample of the silent push notification payload.
{
"to": "[your_device_token]",
"content_available": true,
"apns-priority": 5,
"data": {
"some-key": "some-value"
}
}
At this moment, you will receive an empty notification on your device. This notification should not be visible at all.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:9 (3 by maintainers)
Top GitHub Comments
Was this solved? I don’t think it should be closed yet as our customers are complaining about it.
@areksiekiera nope. It’s still sending empty notifications. We’re waiting for the fix from Expo.