且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

当应用程序在后台运行时,Android中未收到FCM数据消息

更新时间:2022-12-27 10:55:56

所以几周前我就开始使用它,但是通过几个更新(studio,sdk,java)重建了该项目,现在我再也无法使用同一个项目了. /p>

我花了几个小时来浏览网络,尤其是关于这个问题的***,我可以做的回答是这取决于...."我个人认为它可以正常工作,但现在不再工作了,对于你们中的某些人来说可行,但对其他人却无效...

所以我从 FireBase quickstart-android项目开始,我能说的是:

否,当应用程序处于后台时,不会接收到数据消息.也许我会说:当应用程序处于后台时,不再接收数据消息.

因此,我向 Firebase支持问一个问题,期望得到一个好的答案.我真的很失望,答案是:

你好...团队,

感谢您与我们联系.

实际上,不应在后台接收数据有效载荷.数据消息的意图会传递到应用程序,并在onMessageReceived()方法(不会在后台触发)中接收.当应用程序在后台运行时,仅显示消息/通知.

...

此致, K ...

我不知道您对此有何看法,但对我而言,这是一场真正的灾难!

我不知道这是否是暂时的情况,也许某人可以获得更准确的信息,因为我无法相信不再支持后台消息接收.或至少对我们而言,因为根据我的日志,该设备会收到显示以下消息的后台消息:

07-18 15:28:34.371 3068-3068/? W/GCM-DMM: broadcast intent callback: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE flg=0x10000000 pkg=com.google.firebase.quickstart.fcm (has extras) }

但是不会调用onMessageReceive()回调!

重要编辑
构建此类项目,例如通过命令行工具 FireBase quickstart-android项目可以正常运行,但不能正常运行当您从IDE调试按钮构建它时. 如果要通过IDE调试按钮构建项目,请使用 Android Studio 1.5 奇怪,但效果很好).

完整的测试用例可以在此处使用.

>

I face a very strange problem; I had a previous version of my application published using GCM 8.4.0 which worked fine. I updated some code, without changing anything about GCM and I realised that the messages where not received anymore when the application was in background. This on several different devices.

As I was unable to find any explanation, I migrated to FCM. I made few unsuccessful attempts and it began to work !?! Then I was able to send several different messages successfully without changing anything! Houra!!!!

Just before generating my signed APK, I made a last test! Arrggghhhhh.... messages were not received anymore when the application was in background!!!!

I made the test with my server, with Advance REST Request, in the same conditions as I used for successful attempts and no way, it works when the application is in foreground but no more at all when the application is in background!!!

Did you exeperience such problem???

I precise that when I receive a message with the application in foreground and I generate a notification from it, There are 2 different behaviors:

  • When the application is able to receive it in background, the notification remains when I swipe the app out from the recent apps list.

  • When the application is not able to receive it in background, as in my current case, the generated notification is removed when I swipe the application out.

Does it mean something useful?

Edit
I updated to 9.2.0 but the problem remains.

So I got it working few weeks ago but rebuilding the project with several updates, studio, sdk, java, I cannot get the same project working now anymore.

I spent few hours to explore the web, notably *** about this problem and the answer I could do is "It depends...." I personnally got it working, it doesn't work anymore, for some of you it works, for some others it doesn't...

So I started from the FireBase quickstart-android project and what I can say is:

No, data messages are not received when the application is in background. Or maybe I would say: data-messages are not received anymore when the application is in background.

So I ask the question to Firebase-support expecting a good answer. I was really disappointed, the answer is:

Hello ... team,

Thank you for reaching out to us.

Actually data payload is not supposed to be received in background. Data message intents are delivered to the application and received inside onMessageReceived() method (which does not fire in background). Only display messages/ Notifications are delivered when the app is in background.

...

Sincerely, K...

I don't know what you think about that but for me it's a real disaster!

I don't know if it's a temporary situation or not, maybe someone could have more precise information because I cannot believe that background message reception is not supported anymore. Or at least for us because according to my logs, the device receive background messages displaying the following message:

07-18 15:28:34.371 3068-3068/? W/GCM-DMM: broadcast intent callback: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE flg=0x10000000 pkg=com.google.firebase.quickstart.fcm (has extras) }

But the onMessageReceive() callback is not invoked!

IMPORTANT EDIT
Building this kind of project, for example FireBase quickstart-android project from command line tools perfectly works but not when you build it from IDE debug button. If you want to build your project from IDE debug button, use Android Studio 1.5 strange but works perfectly).

Complete test case is available here.