7

Firebase push does not work on some devices when app is closed with only data payload. See this thread: https://github.com/firebase/quickstart-android/issues/41

I know when app is killed by swipe then some OEM kill all the services of the app which directly effect FirebbaseMessagingService and due to this onMessageReceived() method never invoked. I have also tried with high priority FCM but sadly no success. Here are the phones on which I am facing an issue: OnePlus, Lenovo, Huawei.

Currently, I am testing with OnePlus 5, when I change the battery setting to "Don't Optimise" then push notification started working.

I killed the app and run dumpsys package MY-PACKAGE | grep stopped command and I found that app is not stopped. It shows stopped=false. It means app is running.

The concept of push notification is to notify users when app is closed but currently, we are unable to do.

Any suggestion how can I fix this?

AL.
  • 36,815
  • 10
  • 142
  • 281
Faisal Shaikh
  • 3,900
  • 5
  • 40
  • 77
  • Same topic has actually been discussed here in SO for quite some time. See this post -- https://stackoverflow.com/q/39504805/4625829 – AL. Feb 06 '18 at 12:25
  • @AL. you are right but it's still not resolved. – Faisal Shaikh Feb 06 '18 at 12:46
  • I'm having same issue with OnePlus running Android Oreo, will it work if we restart `FirebaseMessagingService` by overriding `onTaskRemoved()` and restarting service again? – global_warming Feb 21 '18 at 17:41
  • @global_warming please try and let me know. – Faisal Shaikh Feb 24 '18 at 06:44
  • I posted you the same answer as in the [github thread](https://github.com/firebase/quickstart-android/issues/41#issuecomment-387469761) because I can't post only link answers. – IgniteCoders May 08 '18 at 17:00

1 Answers1

7

FirebaseMessagingService can receive PushNotification even when app is closed/killed.

But there are some problems in the way. The behavior of the apps changes between development and production, and because of the device provider.

The first thing you have to consider, is when the app is in development, if you force close the app (kill-process), FirebaseMessagingService stop being triggered. But this doesn't happen in production, so don't be aware of this if your APK is signed. link to source

The second thing, is that there some Android phone providers that manage processes by them selfs. We can see an example like Huawei phones and their "Protected applications", which make user decide if want to protect the app or not. Only famous apps are protected on installation like WhatApp or Twitter... link to source

At this point, your FirebaseMessagingService should be triggered, but there are other problems related with memory and processes managed by system (OS). Your Service can be canceled because of the time that it's spending to handle the PushNotification. You can find many ways to handle this problem, but the best way, is Firebase JobDispatcher. link to source

IgniteCoders
  • 4,834
  • 3
  • 44
  • 62
  • This answer is based on the founded solutions for a real project which use **Silect** `PushNotification` (Only `data`key in the `payload` plus `to`& `priority` keys). – IgniteCoders May 08 '18 at 17:12
  • You mean that you are testing a signed apk file and the app is added to protected apps? – IgniteCoders Jun 11 '18 at 12:52