• <tfoot id='MKCz8'></tfoot>

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

      • <bdo id='MKCz8'></bdo><ul id='MKCz8'></ul>

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

      <legend id='MKCz8'><style id='MKCz8'><dir id='MKCz8'><q id='MKCz8'></q></dir></style></legend>

        在收到 Firebase 通知时打开应用 (FCM)

        时间:2023-07-30

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

              <tbody id='bgb5y'></tbody>
            <legend id='bgb5y'><style id='bgb5y'><dir id='bgb5y'><q id='bgb5y'></q></dir></style></legend>

              • <bdo id='bgb5y'></bdo><ul id='bgb5y'></ul>

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

                • <tfoot id='bgb5y'></tfoot>
                  本文介绍了在收到 Firebase 通知时打开应用 (FCM)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想在收到通知时自动打开应用程序,这可以通过 Firebase 和新的 FCM 通知实现吗?

                  I want to open application automatically when notification is received, is this possible with Firebase and new FCM notifications?

                  我知道我可以设置 click_action 但这只是为了自定义在点击通知时启动哪个活动,我需要在收到通知时自动启动的东西.

                  I know I can set click_action but that's only for customizing which activity will start on notification click, I need something that will start automatically when notification is received.

                  我尝试了快速启动消息传递 firebase 示例,并且有一个 onMessageReceived() 方法,但它仅在应用程序处于前台时才有效.应用程序在后台时是否也会执行某些操作?GCM 可以通过直接从收到通知时调用的广播接收器启动活动意图来执行我想要的操作.

                  I tried the quick start messaging firebase sample and there is a onMessageReceived() method but it only works if the app is in foreground. Is there something that will execute while app is in background as well? GCM could do something like what I want here by directly starting activity intent from broadcast receiver which is called when notification is received.

                  推荐答案

                  快速解答:

                  要通过 FCM 自动打开应用程序,您需要使用 data-message,它保证始终调用 FirebaseMessagingService.onMessageReceived() 方法.

                  Quick answer:

                  To automatically open an application via FCM you need to use a data-message, which guarantees to always invoke the FirebaseMessagingService.onMessageReceived() method.

                  然后您可以在 .onMessageReceived() 方法中添加您的逻辑以启动首选活动.

                  Then you can add your logic in the .onMessageReceived() method to start the preferred activity.

                  警告:在没有任何用户交互的情况下启动 UI 对于大多数应用程序来说是一种非常非常糟糕的做法!请在此处阅读 MarkG 答案:如何从服务启动活动?

                  WARNING: launching a UI without any user interaction is a very very bad practice for most of the applications! Please read the MarkG answer here: How to start an Activity from a Service?

                  [...] 中断用户当前正在做的事情被认为是糟糕的设计形式,尤其是从应该在后台运行的事情中.
                  因此,当用户决定是时候进行调查时,您应该考虑使用通知 [...] 来启动所需的活动.[...]

                  [...] Interrupting what the user is currently doing is considered bad design form, especially from something that is supposed to be operating in the background.
                  Therefore, you should consider using a Notification [...] to launch the desired Activity when the user decides it is time to investigate. [...]

                  完整解释:

                  FCM 的工作原理与 GCM 类似,可以接收两种类型的消息:

                  Full explaination:

                  FCM works similarly to GCM and can receive two types of messages:

                  1. 显示消息:
                    有效负载{"notification" : { "body" : "hello world"}}
                    这些消息在应用处于后台时自动显示,如果应用已经处于前台,它们会调用 FirebaseMessagingService.onMessageReceived().

                  2. 数据消息:
                    有效载荷 {"data" : { "key1" : "value1"}}
                    这些消息总是调用 FirebaseMessagingService.onMessageReceived()
                    即使应用已关闭或在后台运行.
                  1. display-messages:
                    payload {"notification" : { "body" : "hello world"}}
                    These messages are automatically displayed when the app is in background and they call FirebaseMessagingService.onMessageReceived() if the app is already in foreground.

                  2. data-messages:
                    payload {"data" : { "key1" : "value1"}}
                    These messages always invoke FirebaseMessagingService.onMessageReceived(),
                    even if the app is closed or in background.

                  click_action 是通知负载的一个参数,因此它适用于显示消息.

                  click_action is a parameter of the notification payload, thus it applies to the display-messages.

                  表示与用户点击通知相关联的操作.
                  如果这是设置一个具有匹配意图过滤器的活动在用户点击通知时启动.

                  Indicates the action associated with a user click on the notification.
                  If this is set an activity with a matching intent filter is launched when user clicks the notification.

                  https://firebase.google.com/docs/cloud-messaging/http-server-ref#notification-payload-support

                  这篇关于在收到 Firebase 通知时打开应用 (FCM)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:带有新 Firebase 云消息传递系统的通知图标 下一篇:Firebase FCM 强制 onTokenRefresh() 被调用

                  相关文章

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

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

                • <legend id='pcylX'><style id='pcylX'><dir id='pcylX'><q id='pcylX'></q></dir></style></legend>

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