Firebase onMessageReceived not called when app is inactive(应用程序处于非活动状态时未调用 Firebase onMessageReceived)
问题描述
我在 Android 上使用 Firebase 云消息传递.
I am using Firebase Cloud Messaging on Android.
- 当应用在前台时,我可以成功接收通知和数据消息.
- 文档指出,如果在应用处于后台时收到通知消息,则 Firebase 将代表应用向系统托盘发送通知.这对我不起作用.
- 如果发送了一条数据消息并且应用程序在后台,那么 onMessageReceived 方法就会被成功调用.
- 最麻烦的场景是当我强制停止应用程序然后尝试发送通知或数据信息.在这种情况下,不会调用 onMessageReceived 方法.
- 我看过很多关于 SO 的文章讨论后台用例,但是我还没有看到任何解释为什么当应用程序完全停止没有收到消息/strong>.
- I can successfully receive notification and data messages when the app is in the foreground.
- The documentation states that if a notification message is received while the app is in the background then Firebase will send a notification to the system tray on behalf of the app. This is not working for me.
- If a data message is sent and the app is in the background then the onMessageReceived method is called successfully.
- The most troubling scenario is when I force stop the application and then try sending a notification or data message. The onMessageReceived method doesn't get called in this situation.
- I have seen a number of articles on SO discussing the background use case, but I have yet to see any explanation for why no messages are being received when the app is stopped entirely.
我的清单中有以下内容:
I have the following in my manifest:
<service android:name=".MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service android:name=".MyInstanceIdService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
这是关于扩展 FirebaseMessagingService 的文档所说的:
This is what the documentation has to say about extending FirebaseMessagingService:
如果您想要在后台接收应用通知之外的任何消息处理,则这是必需的.
This is required if you want to do any message handling beyond receiving notifications on apps in the background.
在后台接收应用程序通知之外的消息处理"是什么意思并不完全清楚.我只能假设他们在谈论关闭应用程序时处理消息.
It's not entirely clear what they mean by "message handling beyond receiving notifications on apps in the background". I can only assume that they are talking about handling messages when the app is closed.
任何帮助将不胜感激.
推荐答案
如果您强制停止应用程序,则在 应用程序重新启动之前您不会收到任何通知.在重新启动应用程序之前,您的任何代码都不会工作.
If you force stop an app you don't get any notifications until the app is restarted. None of your code will work until the app is restarted.
应用的所有服务也将停止,直到用户再次手动启动应用
All services of the app will also be stopped until user manually launches the app again
这篇关于应用程序处于非活动状态时未调用 Firebase onMessageReceived的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:应用程序处于非活动状态时未调用 Firebase onMessageReceived
基础教程推荐
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01