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.

Cannot receive notifications from Firebase console on Android while app is in foreground

See original GitHub issue

React 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:

  1. 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?
  2. 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 folder Examples/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:open
  • Created 6 years ago
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
ericacookseycommented, Oct 12, 2017

@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 }) } })

0reactions
xstablecommented, May 19, 2018

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} ) ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Receive messages in an Android app - Firebase - Google
When your app is in the background, Android directs notification messages to the system tray. A user tap on the notification opens the...
Read more >
Firebase notifications not shown on foreground - Stack Overflow
I'm trying to manage notifications, but I am not able to do nothing with them when app is in foreground. When app is...
Read more >
Firebase Notifications in Background & Foreground in Android
When the app is in foreground, the received messages are processed by the app, and since there's no logic to handle it, nothing...
Read more >
Notifications Not Shown - Mobile Push
If your app is open while sending, you may be hiding the notification using the Foreground Notification Received Event if on our updated...
Read more >
Notifications | FlutterFire
Foreground notifications (also known as "heads up") are those which display for a brief period of time above existing applications, and should be...
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