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.

FCM when app in background

See original GitHub issue

Hi,

The FCM works fine when the app is in foreground and a push comes, but when the app is in background and the system tray notification is clicked , it just opens up the app without passing any intent extras. I have added the click_action in Notification Payload from Advanced option of Firebase Console to open an activity but it dosen’t work. I have also added the intent-filter ( handle backgound app section) as in documentation.

How can i open a specific activity using FCM service along with the data i pass when the app is in background or exit state.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:9
  • Comments:50 (5 by maintainers)

github_iconTop GitHub Comments

19reactions
wassupnaricommented, Jun 9, 2016

Hi @kroikie

I have a follow up question. According to this documentation, the notification will be delivered to the device’s system tray when the app is in background which means onMessageReceived() won’t get called, but I wonder if there’s any way that I can customize the icon in the notification view. Currently, it shows default white icon.

11reactions
pratikbutanicommented, Jul 25, 2016

After a deep search, I have found what is going on: There are two types of messages in FCM:

  • display-messages: These messages only work when your app is in foreground
  • data-messages: Theses messages work even if your app is in background

Firebase team have not developed a UI to send data-messages to your devices.

To achieve this, you have to do a POST to the following URL:

https://fcm.googleapis.com/fcm/send

And the following headers:

  • Key: Content-Type, Value: application/json
  • Key: Authorization, Value: key=<your-server-key>

Body:

{
    "data": {
        "my_custom_key" : "my_custom_value",
        "other_key" : true
     },
    "registration_ids": ["your-device-token","your-device2-token","your-device3-token"]
}

To get your server key, you can find it in the firebase console: Your project -> settings -> Project settings -> Cloud messaging -> Server Key

Hope this helps!

Ref: How to handle notification when app in background in firebase

Read more comments on GitHub >

github_iconTop Results From Across the Web

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. Title, message, and icon ......
Read more >
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 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 >
How to handle FCM Push notification when app is in ... - GitHub
Question 1: Data messages (messages with no notification payload) are handled the same whether the app is in the foreground or background.
Read more >
How to handle FCM notification in backgrounded Android ...
After setting up FCM in Android application, you can use Firebase console to send notifications. When foregrounded application receives a ...
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