question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[expo-notifications][android] Empty notifications received by the users (which are meant to be silent) via FCM

See original GitHub issue

Summary

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:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
mustvladcommented, Feb 22, 2022

Was this solved? I don’t think it should be closed yet as our customers are complaining about it.

3reactions
mustvladcommented, Oct 25, 2021

@areksiekiera nope. It’s still sending empty notifications. We’re waiting for the fix from Expo.

Read more comments on GitHub >

github_iconTop Results From Across the Web

About FCM messages | Firebase Cloud Messaging - Google
Use notification messages when you want FCM to handle displaying a notification on your client app's behalf. Use data messages when you want...
Read more >
[expo-notifications][android] Data-only FCM notification shows ...
Note that when in the foreground the behavior can be set via ... The bug is that these are shown as a blank...
Read more >
Firebase silent apns notification - Stack Overflow
You can send silent APNS messages using the FCM server API ... my iOS app is in the background is to include an...
Read more >
Notifications - Expo Documentation
On Android 13, app users must opt-in to receive notifications via a permissions prompt automatically ... Sending notifications directly through APNs and FCM....
Read more >
Notifications Not Shown - Mobile Push
Devices must be online to receive push notifications. If your device is turned off, in airplane mode, has unstable or no internet connection,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found