Firebase通知有时会跳过onMessageReceived方法 [英] Firebase notification sometimes skip onMessageReceived method

本文介绍了Firebase通知有时会跳过onMessageReceived方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用来自Facebook的Parse时,我可以在开发过程中测试通知(即Play商店中没有应用程序)。但是现在我正在尝试将Firebase应用到我的应用中。我的应用程序尚未发布。我完成了Android端实现,并试图从Firebase控制台发送通知到我的应用程序。但是我的设备永远不会收到通知。这是为什么?我针对的是所有用户,因为firebase没有任何版本或任何主题。
$ b OKAY



因此,我做了一些更多的疑难解答,这里是:我的设备正在接收通知,但它奇怪的是:


  1. 当应用程序打开并且用户正在与之交互时,通知将通过调用 onMessageReceived 的预期路径。


  2. 当应用程序关闭时(不在最近的应用程序中),通知将跳过调用 onMessageReceived 并在状态栏中显示通知。

但是这里是来自FireBase的日志,当 onMessageReceived 被跳过

  05-24 07:15:52.842 D / TimaKeyStoreProvider:TimaSignature不可用
05-24 07 :15:52.842 D / ActivityThread:添加了TimaKeyStore提供程序
05-24 07:15:53.102 D / FirebaseApp:com.google.firebase.auth.FirebaseAuth没有链接。跳过初始化。
05-24 07:15:53.132 D / FirebaseApp:初始化com.google.firebase.iid.FirebaseInstanceId类。
05-24 07:15:53.142 D / FirebaseApp:com.google.firebase.crash.FirebaseCrash未关联。跳过初始化。
05-24 07:15:53.222 I / FA:应用程序测量正在启动,版本:9080
05-24 07:15:53.222 I / FA:启用调试日志记录运行:adb shell setprop log.tag.FA VERBOSE
05-24 07:15:53.352 D / FirebaseApp:初始化com.google.android.gms.measurement.AppMeasurement类。
05-24 07:15:53.352 I / FirebaseInitProvider:FirebaseApp初始化成功
05-24 07:15:53.372 D / AlgorithmsProvider:onCreate
05-24 07:15:53.452 I / FA:找不到标签管理器,因此不会被使用。对于显示消息(带有通知标签的消息),预期的行为是只在应用程序处于前台时调用 onMessageReceived



如果您要使用数据消息(消息没有通知标签),则无法通过控制台进行操作(至少在此之前)。您必须手动创建FCM服务器的发布请求。你可以从这个问题的答案中看到这个帖子请求示例如何在Firebase中的后台应用程序中处理通知


When I was using Parse from Facebook, I could test notification while in development (i.e. no app on the Play Store). But right now I am trying to implement Firebase into my app. My app is not published yet. I am done with android side implementation and am trying to send a notification from the Firebase console to my app. But my device never receives the notification. Why is that? I am targeting "All Users" because firebase does not have a version or any of my topics.

OKAY

So I did some more troubleshooting and here it is: my device is receiving notifications, but it's doing so weirdly:

  1. when the app is open and the user is interacting with it, the notification goes through the expected pathway of calling onMessageReceived.

  2. When the app is closed (not in recent apps either), the notification skips calling onMessageReceived and displays a notification in the status bar.

But then here is the log from FireBase when onMessageReceived is skipped

05-24 07:15:52.842  D/TimaKeyStoreProvider: TimaSignature is unavailable
05-24 07:15:52.842  D/ActivityThread: Added TimaKeyStore provider
05-24 07:15:53.102  D/FirebaseApp: com.google.firebase.auth.FirebaseAuth is not linked. Skipping initialization.
05-24 07:15:53.132  D/FirebaseApp: Initialized class com.google.firebase.iid.FirebaseInstanceId.
05-24 07:15:53.142  D/FirebaseApp: com.google.firebase.crash.FirebaseCrash is not linked. Skipping initialization.
05-24 07:15:53.222  I/FA: App measurement is starting up, version: 9080
05-24 07:15:53.222  I/FA: To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
05-24 07:15:53.352  D/FirebaseApp: Initialized class com.google.android.gms.measurement.AppMeasurement.
05-24 07:15:53.352  I/FirebaseInitProvider: FirebaseApp initialization successful
05-24 07:15:53.372  D/AlgorithmsProvider: onCreate
05-24 07:15:53.452  I/FA: Tag Manager is not found and thus will not be used

解决方案

For the display-messages (messages with notification tag), it's the expected behaviour that the onMessageReceived only called when the app is on foreground.

If you want to use data-messages (message without notification tag), you can't do it via console (at least until this time). You have to manually create post request to FCM server. You can see that post request example from answer to this question How to handle notification when app in background in Firebase.

这篇关于Firebase通知有时会跳过onMessageReceived方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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