当应用程序处于后台时,FCM Intent在何处传递数据? [英] Where is FCM Intent with data delivered, when app is in background?

本文介绍了当应用程序处于后台时,FCM Intent在何处传递数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在我的应用中实现了Firebase,并且正在发送带有额外数据的推送.当我的应用程序位于前台时,我可以正确处理数据并显示我自己的通知,但是当应用程序归位"(未终止)时,Firebase会自动"显示通知时,我在获取数据时遇到问题.根据 DOCS 活动应该获得新的 Intent 的附加功能满足了我的价值观,相反,应用只是回到最前面,恢复了旧状态.

I've implemented Firebase in my app and I'm sending push with extra data. When my app is in foreground I'm handling data properly and showing my own notification, but I have a problem with fetching data, when Firebase shows Notification "automatically" when app was "homed" (not killed). According DOCS Activity should get new Intent with extras fulfilled with my values, instead app just get back to front, old state is restored.

场景:

  1. 打开应用程序,按主页"
  2. 通过Firebase控制台发送推送消息,Firebase正在创建 Notification (通知),而无需调用 onMessageReceived (根据文档中的表格,应该这样)
  3. 当用户选择通知应用程序将以与归位"状态相同的状态出现在最前面时,并且 Intent 通过原始"附加功能实现,用于打开" Activity "顶部
  1. opening app, pressing Home
  2. sending push through Firebase console, Firebase is creating Notification WITHOUT calling onMessageReceived (according to table in docs, it should?)
  3. when user pick notification app will be brought to front in same state as was "homed", and Intent is fulfilled with "original" extras used for open Activity on top

我在 onCreate onNewIntent onResume ( Activity )和 onMessageReceived ( Service ),仅调用 onResume ,在其中打印如下内容:

I have logs in onCreate, onNewIntent, onResume (Activity) and in onMessageReceived (Service), only onResume is called, in which I'm printing extras like below:

if (getIntent().getExtras() != null) {
        for (String key : getIntent().getExtras().keySet()) {
            Object value = getIntent().getExtras().get(key);
            Log.d("Activity onResume", "Key: " + key + " Value: " + value);
        }
    }

推荐答案

同时具有通知和数据有效载荷(背景和前景)的消息.在这种情况下,数据有效载荷将交付给启动程序活动的其他目的.如果要在其他活动中使用它,则必须在数据有效负载上定义click_action.因此,您可以在启动器活动中获得更多的意图.

Messages with both notification and data payload, both background and foreground. In this case the data payload is delivered to extras of the intent of your launcher activity. If you want to get it on some other activity, you have to define click_action on the data payload. So get the intent extra in your launcher activity.

修改:-

文档:-在后台时,应用程序会在通知托盘中接收通知有效载荷,并且仅在用户点击通知时处理数据有效载荷.

From the documentation :- When in the background, apps receive the notification payload in the notification tray, and only handle the data payload when the user taps on the notification.

因此,在单击通知时,使用getIntent()附加项检查启动器活动的oncreate()方法.

So check the launcher activity's oncreate() method with getIntent() extras upon click of notification.

这篇关于当应用程序处于后台时,FCM Intent在何处传递数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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