Android app not receiving Firebase Notification when app is stopped from multi-task tray

前端 未结 6 1276
长发绾君心
长发绾君心 2020-11-21 10:14

I have read a similar question on SO, however, I was not able to get the correct answer from it.

I have a system wherein we send notification to around 500 devices.<

6条回答
  •  南方客
    南方客 (楼主)
    2020-11-21 10:39

    I've been through the same but in my case, it was Xiaomi phones instead of Oppo phones. What actually happens is that when you close the app from system tray, the system kills the app entirely. What that means is your app won't be able to receive notifications via GCM/FCM. WAKE_LOCK permission doesn't help either.

    That does NOT mean that phone is not receiving the notification. It is. It just won't let the apps show it. You can verify this by sending a broadcast from adb and looking at your logcat.

    One possible solution to this problem is to use SyncAdapter. Although it is NOT advised, I've seen some apps using it. Other possible solutions are to use some kind of background service which is always running. Some people also use AlarmManager as it almost never gets killed. My point is - you cannot rely on GCM/FCM for your notifications.

    Let's talk about WhatsApp now -

    In Xiaomi phones, they whitelist or blacklist an app based on certain criteria. If you download an app and if it is in their whitelist, they'll permit the app to show notifications. If not, you already know what happens. But the good thing is that you can change these settings. Look for an app named Security. If you revoke the right permissions, even WhatsApp will stop showing notifications.

提交回复
热议问题