How to Stack Firebase Cloud Messaging Notifications When the Application Is Not Running

Firebase Cloud Messaging doesn't notify when application is running

Firebase Cloud Messaging has two types of messages: notification messages and data messages.

Data messages are used for delivering data to your app. They are always delivered to your application's onMessage handler.

Notification messages are used to show a notification to the user. When your app is active, the messages are delivered to its onMessage handler, so that you can display the notification inside the app. But when the app is not active, notification messages are handled by the system and not delivered to your app's onMessage handler.

It sounds like you're sending a notification message. If you always want the message to be delivered to your applications onMessage, you should send a data message instead.

Also see:

  • the Firebase documentation on message types
  • Firebase onMessageReceived not called when app in background

Firebase notifications when app is closed

Your problem is you using it with notification tray.

See this link

Messages with both notification and data payload, both background and foreground. In this case, the notification is delivered to the device’s system tray, and the data payload is delivered in the extras of the intent of your launcher Activity.

If you using {data:"something"}(data-message) with {notification:"something"}(display-message) while your app is in background the data payload will delivered to extras of the intent but not to the onMessageReceived() method.I assume you implement your code for showing notification, so when your app is in foreground onMessageReceived() is trigger and it display the desire notification you want but when it is not onMessageReceived() no get trigger instead android system will handle it with your notification payload. You just have remove {notification:"something"}(display-message/notification tray) from your server side code to always ensure onMessageReceived().

For anyone keep mention onMessageReceived() will always trigger no matter wether it is not foreground or background please visit this link

Firebase Cloud Messaging is not working after publishing Android app in play store

I finally can solve this problem.

in my case, this problem will occur if you publish your app using Google Play App Signing and you use API key restriction for your Android App in your Google Cloud Platform (GCP).

I would fail to get the FCM ID from the device, that's why our own backend could not send push notification to the Android device because FCM ID was not sent to our backend

here is the solution for this case

  1. Open your Google Play Console, you have to copy the SHA-1 certificate fingerprint. On the left bar, please find Setup --> App Integrity

Sample Image


  1. open credentials section on the GCP console, and select your Android key. you can access it on here: https://console.cloud.google.com/apis/credentials

Sample Image


  1. then add new item, paste the SHA-1 you get in here, and don't forget to save !
    Sample Image

in my case the error that cause this problem was:

java.io.IOException: FIS_AUTH_ERROR

so if my solution doesn't work, you may need to follow this answer

I hope this helps



Related Topics



Leave a reply



Submit