当应用程序在后台运行时,Android中未收到FCM数据消息 [英] FCM data message not received in Android when the application is in background

查看:259
本文介绍了当应用程序在后台运行时,Android中未收到FCM数据消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我面临一个非常奇怪的问题;我使用GCM 8.4.0发布了我的应用程序的先前版本,该版本运行良好.我更新了一些代码,没有更改任何有关GCM的内容,并且意识到当应用程序在后台运行时,不再收到消息.这在几种不同的设备上.

由于我找不到任何解释,因此我迁移到了FCM.我做了几次失败的尝试,然后开始起作用!然后,我可以成功发送几条不同的消息,而无需进行任何更改! Houra !!!!

就在生成我的签名APK之前,我做了最后一次测试! Arrggghhhhh....当应用程序处于后台时,不再收到消息!!!

我使用高级REST请求在服务器上进行了测试,测试条件与成功尝试所使用的条件相同,并且没有任何方法,当应用程序位于前台时,它可以工作,而当应用程序位于后台时,则完全没有任何作用! !!

您遇到这种问题了吗?

我精确地说明,当我在前台看到该应用程序的消息并从中生成通知时,有两种不同的行为:

  • 当应用程序能够在后台接收到它时,当我从最近的应用程序列表中将应用程序滑出时,通知仍会保留.

  • 当应用程序无法在后台接收它时(如我目前的情况),当我将应用程序滑出时,将删除生成的通知.

这意味着有用吗?

修改
我更新到9.2.0,但问题仍然存在.

解决方案

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

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

所以我从 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 Stackoverflow 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.

这篇关于当应用程序在后台运行时,Android中未收到FCM数据消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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