Cannot receive notifications from Firebase console on Android while app is in foreground
See original GitHub issueReact Native Version: 0.47.2 Device: LG V20 (Model number LG-H990ds) Android Version: 7.0 App is running in the foreground
I’m testing out using Firebase Cloud Messaging with our React Native app and went through the setup instructions for this library on Android. I saw that the app receives notifications just fine while in the background, but in the foreground, the app doesn’t receive any push notifications.
For testing, I set up a new project in the Firebase console and I’m using the Notifications Composer on the Firebase console to send push notifications. All I’m sending is a simple notification with “Hello world!” as the message, and it’s not showing up in the notification tray when the app is in the foreground, even though I have the local notification publisher set up. I downloaded the example project and I also wasn’t seeing a push notification when the app is in the foreground.
I have two questions:
- When the example app is in the foreground, is a notification expected to appear in the system tray when sending it through the Firebase console?
- Is there something wrong with my setup? For the example project, I did the following:
- Cloned the repository
- Opened the project in Android studio (the folder
Examples/simple-fcm-client/android/
) - Created a new project in the Firebase console with the example project’s bundle ID
- Downloaded the google-services.json file and put it into the project, as the console instructed.
- Ran
npm install
in the root folder of the example project (the folderExamples/simple-fcm-client
) - Ran
npm start
in the root folder of the example project - Hit the “run” button in Android studio and selected my device
I started debugging some of the code in the library and saw some obvious issues. For one, the intent in the onMessageReceived
function within the class MessagingService
passes in an action named “com.evollu.react.fcm.ReceiveNotification”, and there’s nothing in the Android manifest listening for an action with that name. After correcting this naming issue and adding an intent filter in the Android manifest, I noticed that the SendNotificationTask
assumes the intent has some extras with properties such as body
, title
, etc., but the intent has a RemoteMessage
object as its single extra under the data
key.
Please let me know if there’s something wrong with my project setup that’s causing the issue, otherwise I’m going to have to submit some major changes to the Android side of the code, and update the setup instructions.
Issue Analytics
- State:
- Created 6 years ago
- Comments:12 (5 by maintainers)
Top GitHub Comments
@Elethier I found a workaround:
// This is triggered regardless of app state FCM.on(FCMEvent.Notification, async (notif) => { if (notif.fcm && notif.fcm.body) { // A new notification was received FCM.presentLocalNotification({ title: 'my title', body: notif.fcm.body, big_text: notif.fcm.body, show_in_foreground: true }) } })
I don’t get any output, even If I do like @ericacooksey described.
I’ve checked till RNFIRMessaging.presentLocalNotification(details); and found that the details-Object has data and this Function is fired in /node_modules/react-native-fcm/index.js.
Are there permissions needed to use presentLocalNotification ? I’m on Android 8.0
What woud be the way to send this Payload?
FCM.send( {payload-object-here} )
?