• <bdo id='3xyo9'></bdo><ul id='3xyo9'></ul>

    <small id='3xyo9'></small><noframes id='3xyo9'>

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

        Android:订阅 Firebase Cloud Messaging(FCM) 主题

        时间:2023-07-30

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

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

              <tfoot id='tglIO'></tfoot>

                <tbody id='tglIO'></tbody>
                <legend id='tglIO'><style id='tglIO'><dir id='tglIO'><q id='tglIO'></q></dir></style></legend>
                • <bdo id='tglIO'></bdo><ul id='tglIO'></ul>

                  本文介绍了Android:订阅 Firebase Cloud Messaging(FCM) 主题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  根据 Firebase 云消息传递文档,订阅用户到我需要调用的主题

                  According to Firebase cloud messaging documentation, for subscribing a user to a topic I need to call

                  FirebaseMessaging.getInstance().subscribeToTopic("news");
                  

                  1. 在我的应用程序中,我需要所有用户都订阅我的云消息传递主题.由于返回值为 void,问题是如何我可以理解订阅成功了吗?
                  2. 每次我都调用 subscribeToTopic 是不是一种不好的做法?应用程序启动了吗?
                  1. In my application, I need all users to be subscribed to my cloud messaging topic. Since return value is void, the question is how can I understand that subscription was successful?
                  2. Is it a bad practice to call subscribeToTopic each time my application starts?

                  推荐答案

                  1.我怎么知道订阅成功了?

                  您现在可以通过添加 addOnSuccessListener()

                  FirebaseMessaging.getInstance().subscribeToTopic("news").addOnSuccessListener(new OnSuccessListener<Void>() {
                          @Override
                          public void onSuccess(Void aVoid) {
                              Toast.makeText(getApplicationContext(),"Success",Toast.LENGTH_LONG).show();
                          }
                      });
                  

                  原文:

                  文档中没有明确提及订阅成功时收到的响应.

                  There is nothing explicitly mentioned in the docs about a response received when the subscription is successful.

                  但是,如果您需要强制所有用户订阅特定主题,则应在首次安装应用时调用 subscribeToTopic.这很可能会确保连接到互联网(因为它可能是通过 Play 商店下载和安装的)并且订阅成功.

                  However, if you need to mandate all of your users to be subscribed to a specific topic, you should call the subscribeToTopic on your app's first install. This will most likely make sure that there is a connection to the internet (since it's probably been downloaded and installed via the Play Store) and the subscription successful.

                  但是,如果您想确定,您也可以通过自己的 App Server 处理他的检查.如 docs 中所述:

                  However, if you want to make sure, you can also handle he checking via your own App Server. As mentioned in the docs:

                  您可以利用实例 ID API 从服务器端执行基本主题管理任务.给定客户端应用实例的注册令牌,您可以执行以下操作:

                  You can take advantage of Instance ID APIs to perform basic topic management tasks from the server side. Given the registration token(s) of client app instances, you can do the following:

                  • 了解有关客户端应用实例订阅的详细信息,包括每个主题名称和订阅日期.请参阅获取有关应用实例的信息.

                  检查注册令牌,如果它们没有成功订阅您的主题,向它发送通知,它将触发您的客户端应用调用 subscribeToTopic.

                  Check through the registration tokens, if they haven't been successfully subsribed to your topic, send a notification to it where it will trigger your client app to call subscribeToTopic.

                  2.每次我的应用程序启动时调用 subscribeToTopic 是不是一种不好的做法?

                  从评论部分添加:在应用启动时订阅应该没问题.

                  Adding it in from the comments section: Subscribing on app start should be fine.

                  感谢@FrankvanPuffelen 的验证.:)

                  Thank you @FrankvanPuffelen for verifying. :)

                  这篇关于Android:订阅 Firebase Cloud Messaging(FCM) 主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:从android中的firebase发送通知时没有通知声音 下一篇:如何在应用程序未运行时堆叠 Firebase 云消息传递通知?

                  相关文章

                  <legend id='QyaEn'><style id='QyaEn'><dir id='QyaEn'><q id='QyaEn'></q></dir></style></legend>
                • <small id='QyaEn'></small><noframes id='QyaEn'>

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

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

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