<legend id='7OAVs'><style id='7OAVs'><dir id='7OAVs'><q id='7OAVs'></q></dir></style></legend>
  1. <small id='7OAVs'></small><noframes id='7OAVs'>

      <bdo id='7OAVs'></bdo><ul id='7OAVs'></ul>
  2. <tfoot id='7OAVs'></tfoot>
    <i id='7OAVs'><tr id='7OAVs'><dt id='7OAVs'><q id='7OAVs'><span id='7OAVs'><b id='7OAVs'><form id='7OAVs'><ins id='7OAVs'></ins><ul id='7OAVs'></ul><sub id='7OAVs'></sub></form><legend id='7OAVs'></legend><bdo id='7OAVs'><pre id='7OAVs'><center id='7OAVs'></center></pre></bdo></b><th id='7OAVs'></th></span></q></dt></tr></i><div id='7OAVs'><tfoot id='7OAVs'></tfoot><dl id='7OAVs'><fieldset id='7OAVs'></fieldset></dl></div>

    1. 当应用程序是后台 FCM 时如何检索通知消息 intent.getExtras()

      时间:2023-07-29
    2. <i id='QosDU'><tr id='QosDU'><dt id='QosDU'><q id='QosDU'><span id='QosDU'><b id='QosDU'><form id='QosDU'><ins id='QosDU'></ins><ul id='QosDU'></ul><sub id='QosDU'></sub></form><legend id='QosDU'></legend><bdo id='QosDU'><pre id='QosDU'><center id='QosDU'></center></pre></bdo></b><th id='QosDU'></th></span></q></dt></tr></i><div id='QosDU'><tfoot id='QosDU'></tfoot><dl id='QosDU'><fieldset id='QosDU'></fieldset></dl></div>
        <legend id='QosDU'><style id='QosDU'><dir id='QosDU'><q id='QosDU'></q></dir></style></legend>
          <tbody id='QosDU'></tbody>

        <small id='QosDU'></small><noframes id='QosDU'>

            • <tfoot id='QosDU'></tfoot>
                <bdo id='QosDU'></bdo><ul id='QosDU'></ul>

                本文介绍了当应用程序是后台 FCM 时如何检索通知消息 intent.getExtras()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在使用 FCM 进行简单通知

                I am using FCM for Simple notification

                当应用程序处于前台时,一切正常.我在 onMessageReceived 方法中收到通知和数据消息.

                When the app is in foreground, everything working properly. I am getting a notification plus the data message inside the onMessageReceived method.

                但是当应用程序处于后台时,我会在系统托盘中收到通知.当我单击控件时,它会转到主要活动.当我解析 intent.getExtras(); 时,我只得到这个关键数据 - google.sent_timefromgoogle.message_id, collapse_key.

                But when app is in background, I am getting notification in system tray. And when I click on the control, it goes to the main activity. And When I parse intent.getExtras();, I am getting only this key data - google.sent_time, from, google.message_id, collapse_key.

                如何从intent.getExtras()获取系统托盘中可见的通知消息标题和消息?

                How to get the notification message title and Message which is visible in system tray from intent.getExtras()?

                我正在使用 FCM 控制台发送通知我没有专门的服务器来执行此操作.

                I am using FCM console for sending notification I don't have my dedicated server to do this.

                接收消息的代码:

                final Bundle extras = intent.getExtras(); 
                final Set<String> keySet = extras.keySet(); 
                final Iterator<String> iterator = keySet.iterator(); 
                while (iterator.hasNext()) {     
                    final String key = iterator.next(); 
                    final Object o = extras.get(key); 
                    System.out.println(key + ":" + o); 
                } 
                

                推荐答案

                如 Handling Messages for Android FCM docs,如果你发送的payload既有通知又有数据,会单独处理.通知部分将由通知托盘处理,而数据部分将在 Intent 的附加部分中.

                As seen in the Handling Messages for Android FCM docs, if the payload you sent has both notification and data, it will be handled separately. The notification part will be handled by the Notification Tray, while the data part will be in the extras of the intent.

                AFAIK,当应用程序处于后台时(始终由通知托盘处理),无法获取通知负载.但是,您可以将自定义键值对添加到数据负载中,如下所示:

                AFAIK, there is no way to get the notification payload when the app is in background (always handled by the Notification Tray). However, what you could do is add custom key-value pairs to your data payload instead, like so:

                {
                "data": {
                      "notification_title": "title here",
                      "notification_message": "message here"
                     }
                }
                

                当然,您必须确保 notification_titlenotification_message 的数据值与您在通知负载中设置的值相同.然后像往常一样从 Intent extras 中检索它.

                Of course you'll have to make sure that the data value for notification_title and notification_message is the same as to what you set it in the notification payload. Then just retrieve it from the Intent extras like usual.

                这篇关于当应用程序是后台 FCM 时如何检索通知消息 intent.getExtras()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:使用“new"获取 403 响应.Firebase 云消息传递 API 下一篇:Firebase + 权限

                相关文章

                  <bdo id='AENMb'></bdo><ul id='AENMb'></ul>
                <i id='AENMb'><tr id='AENMb'><dt id='AENMb'><q id='AENMb'><span id='AENMb'><b id='AENMb'><form id='AENMb'><ins id='AENMb'></ins><ul id='AENMb'></ul><sub id='AENMb'></sub></form><legend id='AENMb'></legend><bdo id='AENMb'><pre id='AENMb'><center id='AENMb'></center></pre></bdo></b><th id='AENMb'></th></span></q></dt></tr></i><div id='AENMb'><tfoot id='AENMb'></tfoot><dl id='AENMb'><fieldset id='AENMb'></fieldset></dl></div>
                <legend id='AENMb'><style id='AENMb'><dir id='AENMb'><q id='AENMb'></q></dir></style></legend>

                    <small id='AENMb'></small><noframes id='AENMb'>

                    <tfoot id='AENMb'></tfoot>