<tfoot id='zdLqM'></tfoot>
  1. <legend id='zdLqM'><style id='zdLqM'><dir id='zdLqM'><q id='zdLqM'></q></dir></style></legend>

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

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

      如何处理 FirebaseInstanceId.getInstance().getToken() = null

      How to handle FirebaseInstanceId.getInstance().getToken() = null(如何处理 FirebaseInstanceId.getInstance().getToken() = null)

      <legend id='30eem'><style id='30eem'><dir id='30eem'><q id='30eem'></q></dir></style></legend>

      1. <small id='30eem'></small><noframes id='30eem'>

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

                <bdo id='30eem'></bdo><ul id='30eem'></ul>
                  <tbody id='30eem'></tbody>
                本文介绍了如何处理 FirebaseInstanceId.getInstance().getToken() = null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我刚刚迁移到 FCM.我添加了从 FirebaseInstanceIdService 扩展的类,以便在适当的时候接收 refreshedToken.

                I have just migrated to FCM. I have added my class that extends from FirebaseInstanceIdService to receive a refreshedToken as and when appropriate.

                我的问题是针对用户第一次安装我的应用程序并且由于某种原因无法从 onTokenRefresh 接收注册 ID 的情况.我们应该如何处理这件事?我可以从我的 FirebaseInstanceIdService 类中设置一个广播接收器,它会在收到注册 ID 时通知 Main 活动吗?

                My question is specific to the case when user installs my app first time and due to some reason, unable to receive a registration Id from onTokenRefresh. How are we supposed to handle this? Can I set a broadcast receiver from my FirebaseInstanceIdService class which will notify the Main activity when a registration Id is received?

                推荐答案

                • 如果您的设备没有连接到互联网 onTokenRefresh() 永远不会被调用,您应该通知用户他/她的设备没有互联网连接
                • firebase 有自己的网络更改侦听器,当设备连接到互联网时,然后尝试获取令牌并返回它,此时您可以通过发送本地广播接收器来告知您的主要活动,即接收到注册令牌.

                  • if your device have no connection to the internet onTokenRefresh() is never called and you should notify to user his/her device has no internet connection
                  • firebase has its own network change listener and when a device connected to the internet then try to get token and return it, at this time you can tell your main activity by sending a local broadcast receiver that registration token is received.
                  • 使用以下代码:

                        @Override
                    public void onTokenRefresh() {
                    
                        // Get updated InstanceID token.
                        String refreshedToken = FirebaseInstanceId.getInstance().getToken();
                    
                        Log.d("FCN TOKEN GET", "Refreshed token: " + refreshedToken);
                    
                        final Intent intent = new Intent("tokenReceiver");
                        // You can also include some extra data.
                        final LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(this);
                        intent.putExtra("token",refreshedToken);
                        broadcastManager.sendBroadcast(intent);
                    
                    
                    }
                    

                    在您的主要活动中:

                        public class MainActivity extends AppCompatActivity {
                    
                    @Override
                    protected void onCreate(Bundle savedInstanceState) {
                        super.onCreate(savedInstanceState);
                        setContentView(R.layout.activity_splash);
                       LocalBroadcastManager.getInstance(this).registerReceiver(tokenReceiver,
                                new IntentFilter("tokenReceiver"));
                    
                    }
                    
                    BroadcastReceiver tokenReceiver = new BroadcastReceiver() {
                        @Override
                        public void onReceive(Context context, Intent intent) {
                            String token = intent.getStringExtra("token");
                            if(token != null)
                            {
                                //send token to your server or what you want to do
                            }
                    
                        }
                    };
                    
                    }
                    

                    这篇关于如何处理 FirebaseInstanceId.getInstance().getToken() = null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                    本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                When does a FCM token expire?(FCM 令牌何时到期?)
                Firebase Cloud Messaging (FCM) - Launch Activity when user clicks the notification with extras(Firebase Cloud Messaging (FCM) - 当用户点击带有附加功能的通知时启动活动)
                Implement Firebase inside of a Library(在库中实现 Firebase)
                Firebase Backward compatibility with GCM(Firebase 与 GCM 的向后兼容性)
                Receiving the FCM notifications multiple times on Nougat(在 Nougat 上多次接收 FCM 通知)
                Push Notifications are delivered but didReceiveRemoteNotification is never called Swift(推送通知已交付,但 didReceiveRemoteNotification 从未被称为 Swift)
                  <bdo id='mo3mV'></bdo><ul id='mo3mV'></ul>

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

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

                      <tfoot id='mo3mV'></tfoot>

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

                          <tbody id='mo3mV'></tbody>