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

查看:213
本文介绍了Firebase onMessageReceived不在应用程序处于非活动状态时调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Android上使用Firebase Cloud Messaging。


  • 当应用处于前台时,我可以成功接收通知和数据消息。

  • 文档指出,如果在应用在后台中收到通知消息,则Firebase将代表系统托盘发送通知的应用程序。这对我来说是不起作用

  • 如果发送数据消息,并且应用程序在后台,则onMessageReceived方法被成功调用。 最令人不安的方案是当我强行停止应用程序然后尝试发送通知或数据讯息。在这种情况下 onMessageReceived方法不会被调用

  • 在讨论背景用例时,我已经看到了大量的文章,但是我还没有看到为什么没有收到消息



我的清单中包含以下内容:

 < 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的文档说明:


如果您想要在接收到后台应用程序的通知之后执行任何消息处理,则需要此选项。

除了在后台接收应用程序通知之外的消息处理,它们并不完全清楚它们的含义。我只能假设他们正在讨论应用程序关闭时处理消息。



任何帮助将不胜感激。

强行停止应用,则在应用重新启动之前,您不会收到任何通知。在应用程序重新启动之前,您的代码都不会起作用。



应用程序的所有服务也会停止,直到用户再次手动启动应用程序


I am using Firebase Cloud Messaging on Android.

  • 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>

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.

Any help would be greatly appreciated.

解决方案

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天全站免登陆