当应用程式关闭/被杀死时,Android中的Firebase推送通知问题 [英] Firebase push notification issue in Android when app is closed/killed

查看:818
本文介绍了当应用程式关闭/被杀死时,Android中的Firebase推送通知问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

仅在关闭数据有效载荷的应用程序时,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,但遗憾的是没有成功.以下是我遇到问题的手机:OnePlus,联想,华为.

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进行测试,当我将电池设置更改为"Do n't Optimize"时,推送通知便开始工作.

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命令,但我发现该应用程序没有停止.它显示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,但是还有其他与系统管理的内存和进程有关的问题.您的Service可能因为处理PushNotification所花费的时间而被取消.您可以找到许多解决此问题的方法,但是最好的方法是链接至源代码

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推送通知问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆