当应用仅使用数据负载关闭时,Firebase 推送无法在某些设备上运行.看到这个线程:https://github.com/firebase/quickstart-android/issues/41
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
我知道当应用程序被滑动杀死时,一些 OEM 会杀死直接影响 FirebbaseMessagingService 的应用程序的所有服务,并且由于这个 onMessageReceived() 方法从未被调用过.我也尝试过高优先级的 FCM,但遗憾的是没有成功.以下是我遇到问题的手机:一加、联想、华为.
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.
目前,我正在使用 OnePlus 5 进行测试,当我将电池设置更改为不优化"时,推送通知开始工作.
Currently, I am testing with OnePlus 5, when I change the battery setting to "Don't Optimise" then push notification started working.
我杀死了应用程序并运行 dumpsys package MY-PACKAGE |grep 停止
命令,我发现应用程序没有停止.它显示 stopped=false
.这意味着应用程序正在运行.
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?
FirebaseMessagingService
可以接收 PushNotification
即使应用程序关闭/杀死.
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.
您首先要考虑的是,当应用程序处于开发阶段时,如果您强制关闭应用程序(kill-process),FirebaseMessagingService
将停止被触发.但这不会在生产中发生,因此如果您的 APK 已签名,请不要注意这一点.链接到来源
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
第二件事是,有一些 Android 手机供应商自行管理流程.我们可以看到像华为手机及其受保护的应用程序"这样的例子,它让用户决定是否要保护应用程序.只有著名的应用程序在安装时受到保护,例如 WhatApp 或 Twitter...链接到源代码
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
此时,您的 FirebaseMessagingService
应该会被触发,但还有其他与系统 (OS) 管理的内存和进程相关的问题.您的 Service
可能会因为处理 PushNotification
所花费的时间而被取消.你可以找到很多方法来处理这个问题,但最好的方法是 Firebase JobDispatcher.链接到来源
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
这篇关于应用程序关闭/终止时 Android 中的 Firebase 推送通知问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!