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.

[Bare] expo-notifications does not handle notification payload on Android

See original GitHub issue

🐛 Bug Report

Environment

Expo CLI 3.18.6 environment info: System: OS: macOS 10.15.4 Shell: 5.7.1 - /bin/zsh Binaries: Node: 13.13.0 - ~/.nvm/versions/node/v13.13.0/bin/node npm: 6.14.4 - ~/.nvm/versions/node/v13.13.0/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman IDEs: Android Studio: 3.6 AI-192.7142.36.36.6241897 Xcode: 11.4.1/11E503a - /usr/bin/xcodebuild npmPackages: react: 16.13.1 => 16.13.1 react-native: 0.62.2 => 0.62.2

  • Standalone (bare workflow)
  • Android

Steps to Reproduce

Send a FCM message with both notification and data payload:

    {
      notification: {
        title: "Test",
        body: "Hello world!",
        badge: "1",
        sound: "default",
      },
      data: {
        key: value,
      },
	}

When app is in the background, FCM itself handles the notification payload and shows the notification.

When app is in the foreground, FCM will not do anything, but expo-notifications does not handle the notification payload either. So an empty notification is shown.

Expected Behavior

According to Firebase doc, we should check the payload if the app’s in the foreground.

    // Check if message contains a data payload.
    if (remoteMessage.getData().size() > 0) {
        Log.d(TAG, "Message data payload: " + remoteMessage.getData());

        if (/* Check if data needs to be processed by long running job */ true) {
            // For long-running tasks (10 seconds or more) use WorkManager.
            scheduleJob();
        } else {
            // Handle message within 10 seconds
            handleNow();
        }

    }

    // Check if message contains a notification payload.
    if (remoteMessage.getNotification() != null) {
        Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
    }

Actual Behavior

expo-notifications, however, only extract data from the message, so notification is not handled:

https://github.com/expo/expo/blob/c37c9afa3674c6dd49f251f21b0532a69545f9e4/packages/expo-notifications/android/src/main/java/expo/modules/notifications/FirebaseListenerService.java#L88-L97

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
sjchmielacommented, May 4, 2020

Hey @robertying, you may be interested to know that expo-notifications@0.1.4 adds support for custom notifications icons and colors in a similar manner as Firebase does it. 🙂

0reactions
sjchmielacommented, Apr 27, 2020

Hey @arberK! If I understood you correctly, you’re asking how one can handle (i.e. receive information) about the fact that a user tapped a group of notifications. Unfortunately, Android does not provide us with information about such event, so there’s no way for expo-notifications to provide you with required information. Good news is that it’s an Android thing so users are used to it and don’t expect your app to act when they tap on a group of notifications. 🙂

Read more comments on GitHub >

github_iconTop Results From Across the Web

Notifications - Expo Documentation
Handle notifications when the app is in foreground,; Imperatively dismiss notifications from Notification Center/tray,; Create, update, delete Android ...
Read more >
[Expo] Android notifications are not received in-app when it's ...
First of all: the authors changed the notification payload. In the new version, there are two listeners for receiving notification and receiving ...
Read more >
How to handle notification when app in background in Firebase
When you are in background, FCM will showing notification in system tray based on the info from notification payload.
Read more >
expo-notifications-bux-fix v0.12.0 - npm.io
handle notifications when the app is in foreground,; imperatively dismiss notifications from Notification Center/tray,; create, update, delete Android ...
Read more >
Push Notification Not Working When App Is Closed Android
AWS Amplify provides two push notification configuration functions to This process does not open the closed app into your Android ...
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