应用程序处于非活动状态时未调用 Firebase onMessageReceived [英] Firebase onMessageReceived not called when app is inactive

查看:20
本文介绍了应用程序处于非活动状态时未调用 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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