I'm testing Firebase Push notifications, sending a notification from the Firebase composer panel, and I noticed that if I close the app process from App Information panel, the push notifications sent doesn't reach the device. Even if I start again the app the notification is lost and is never received.
I also tryed this:
close the app process -> shut down the device -> power on the device -> send a notification... and the notification is not received!
It seems that firebase can only receive notifications if the device has the app started and not 100% closed, I mean, closing it just with back key but not killing the app process.
How is this possible? It is supossed that firebase should receive notifications even with the app closed.
I'm testing on a Nexus 5X with Android 8.0 and I'm using the last version of Firebase push Notifications
.
Push notification is other than a pop-up you might see on a website or when you're in a mobile app. Pop-ups are only activated if you're using the app or website, whereas push notifications don't require the app to be open. There are also pull notifications, which are activated manually by the user.
Apple does not offer a way to handle a notification that arrives when your app is closed (i.e. when the user has fully quit the application or the OS had decided to kill it while it is in the background). If this happens, the only way to handle the notification is to wait until it is opened by the user.
Firebase notifications behave differently depending on the foreground/background state of the receiving app. If you want foregrounded apps to receive notification messages or data messages, you'll need to write code to handle the onMessageReceived callback.
Settings > Sounds & Vibration > Do Not Disturb: if this setting is enabled, Push Notifications will not be received. Make sure this is disabled. Settings > General > Background App Refresh: this setting allows the app to run in the background and must be turned on.
Sorry for the late, but hope this help next users that will have this problem because there is no answer selected as "Solution".
When setup correctly the service, this will work even the app is closed. That because, Firebase Messages travel by Google Play Services so closing your app doesn't have a relation with the service.
At first, notification never came. By searching in the device settings I saw that the energy saving system for my app was active (when closed was removed from stack) so notification was sent but my app couldn't take and display these.
After disabling that option, I've test many time and I found that sometimes notification come with a late of 2-3 minutes when app is completely closed. Sometimes it touch the 5 minutes. You need to be patient and it will come!
Instead, When app is opened or closed simply by back button, notification come in few seconds.
In your AndroidManifest.xml file remove android:exported=false
from your Messaging service.
Explanation: When your app is completely killed or removed from back stack. OS tries to restart the messaging service but if there is android:exported=false
in your manifest file then OS will not able to restart the service because such service can only be restarted by the same app.
Reference: https://developer.android.com/guide/topics/manifest/service-element#exported
It seems that firebase can only receive notifications if the device has the app started and not 100% closed, I mean, closing it just with back key but not killing the app process.
No, FCMs are sent to all the devices that have Google Play services and the targeted application. That is why it is called Push Notifications.
Your application also get notifications when it is running, to handle those you need to override
onMessageRecieved(RemoteMessage mes);
There could be many reasons for the app not getting notifications. Some of them could be :
Messaging Services not included in the Manifest
Play services not configured correctly. Or not present in the Phone.
Sometimes Latency is High (rarely). I noticed it sometimes take take about 2-3 minutes after composing.
SHA1 fingerprint not registered in Console and/or updated google-services.json not present in sources.
Uninstall and reinstall the app. So that token Regeneration may take place.
Please follow this link to get started with messaging.
https://firebase.google.com/docs/cloud-messaging/android/client
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With