9

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.

Dharmishtha
  • 1,229
  • 8
  • 21
NullPointerException
  • 32,153
  • 66
  • 194
  • 346
  • 1
    There are two types of messages - notification message and data message. Which one do you use? – Sergei Emelianov Dec 18 '17 at 12:51
  • I android latest version 7.0+ introduced DOZE which not allow background service when app kill or not running. https://developer.android.com/about/versions/nougat/android-7.0-changes.html – Rahul Chaube Dec 18 '17 at 12:53
  • Possibly helpful [post](https://stackoverflow.com/q/39504805/4625829) – AL. Dec 18 '17 at 13:36
  • @SerjArdovic how can I know that? I'm using this to send the message: https://console.firebase.google.com/project/_/notification/compose?authuser=0 – NullPointerException Dec 18 '17 at 14:41
  • My device is running on Android 8.0 and I am using firebase-messaging:11.6.0, everything works fine. Even if app is completely closed still I am getting notifications. – coder3101 Dec 18 '17 at 16:57

5 Answers5

6

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.

3

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

priwiljay
  • 2,048
  • 1
  • 14
  • 19
1

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

coder3101
  • 3,175
  • 1
  • 19
  • 24
  • 1
    SHA1 is not registered in the console but because it is optional. Will it affect? Is that documented anywhere? – NullPointerException Dec 19 '17 at 12:32
  • It is always better to register it. Make sure for debug purpose you submit debug key's sha and release key's for release versions. Here is how to get SHA1 for keys https://stackoverflow.com/questions/15727912/sha-1-fingerprint-of-keystore-certificate – coder3101 Dec 19 '17 at 12:36
  • 1
    why is better? in the documentation from the website it's told that they are optional and just for other services, not for push – NullPointerException Dec 19 '17 at 14:54
  • SHA1 Hash allows the backend to identify the app as legit or not. To prevent unauthorized or modded versions access to firebase services. Have you implemented everything else as mentioned in the my Post's link. If so please let me know. – coder3101 Dec 19 '17 at 15:28
0

Have you added firebase services on Java code? Here is the link: firebase/quickstart-android

You have to add those 3 java file in java folder and also add those service name in AndroidManifest.xml

abir-cse
  • 345
  • 2
  • 11
0

if you are sending it from your firebase console it sends a notification message so those you will not get if your app is closed, you need to send messages that have the data payload which the console does not do.

https://firebase.google.com/docs/cloud-messaging/concept-options#notifications_and_data_messages

tyczj
  • 66,691
  • 50
  • 172
  • 271