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
- Open your Google Play Console, you have to copy the SHA-1 certificate fingerprint. On the left bar, please find Setup --> App Integrity
- 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
- then add new item, paste the SHA-1 you get in here, and don't forget to save !
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
What Happens to Older Clients When You Migrate an App Server from Gcm to Fcm
Running Google Map Application on Android Emulator
Android: How to Return Async JSONobject from Method Using Volley
Eclipse Indexer Errors When Using Stl with Android Ndk
How to Set Text Color of a Textview Programmatically
How to Paging Query from Firebase Using Android Firebaseui
How to Create a Service Which Continuously Monitors App Usage Information
Shaking/Wobble View Animation in Android
Android: Change Tab Text Color Programmatically
How to Work-Around the Blank Title in Pagertitlestrip and Pagertabstrip
Android Listview Child View Setenabled() and Setclickable() Do Nothing
Two Main Activities in Androidmanifest.Xml
Is There a Workaround for The Android Browser Bug with CSS-Position and Clickable Areas