[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:
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (6 by maintainers)
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. 🙂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. 🙂