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

          <bdo id='n3MzJ'></bdo><ul id='n3MzJ'></ul>

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

        Firebase onTokenRefresh() 未被调用

        时间:2023-07-30
          <bdo id='jgQyF'></bdo><ul id='jgQyF'></ul>
          <i id='jgQyF'><tr id='jgQyF'><dt id='jgQyF'><q id='jgQyF'><span id='jgQyF'><b id='jgQyF'><form id='jgQyF'><ins id='jgQyF'></ins><ul id='jgQyF'></ul><sub id='jgQyF'></sub></form><legend id='jgQyF'></legend><bdo id='jgQyF'><pre id='jgQyF'><center id='jgQyF'></center></pre></bdo></b><th id='jgQyF'></th></span></q></dt></tr></i><div id='jgQyF'><tfoot id='jgQyF'></tfoot><dl id='jgQyF'><fieldset id='jgQyF'></fieldset></dl></div>

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

        • <legend id='jgQyF'><style id='jgQyF'><dir id='jgQyF'><q id='jgQyF'></q></dir></style></legend>
            <tfoot id='jgQyF'></tfoot>
              <tbody id='jgQyF'></tbody>

                  本文介绍了Firebase onTokenRefresh() 未被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在我的日志中的 MainActivity 中,我可以看到使用 FirebaseInstanceId.getInstance().getToken() 的令牌并显示生成的令牌.但似乎在我的 MyFirebaseInstanceIDService 延伸到 FirebaseInstanceIdService 的地方,onTokenRefresh() 没有被调用,在这个函数中它被称为令牌最初是在此处生成的.我需要调用 sendRegistrationToServer() 这就是为什么我想知道它为什么不进入 onTokenRefresh() 的原因.

                  In my MainActivityin my log, I can see the token using FirebaseInstanceId.getInstance().getToken() and it display the generated token. But it seems like in my MyFirebaseInstanceIDService where it is extends to FirebaseInstanceIdService, the onTokenRefresh() is not called, where in this function it was said that the token is initially generated here. I needed to call sendRegistrationToServer() that's why I'm trying to know why it doesn't go in the onTokenRefresh().

                  这是我的代码

                  public class MyFirebaseInstanceIDService  extends FirebaseInstanceIdService {
                  
                  
                  @Override
                  public void onTokenRefresh() {
                      // Get updated InstanceID token.
                      String refreshedToken = FirebaseInstanceId.getInstance().getToken();
                      Log.d(TAG, "Refreshed token: " + refreshedToken);
                  
                          sendRegistrationToServer(refreshedToken);
                      }
                  }
                  

                  推荐答案

                  仅在生成新令牌时调用 FirebaseInstanceIdService 中的 onTokenRefresh.如果您的应用之前已安装并生成了令牌,则不会调用 onTokenRefresh.尝试卸载并重新安装应用程序以强制生成新令牌,这将导致 onTokenRefresh 被调用.

                  onTokenRefresh in FirebaseInstanceIdService is only called when a new token is generated. If your app was previously installed and generated a token then onTokenRefresh would not be called. Try uninstalling and reinstalling the app to force the generation of a new token, this would cause onTokenRefresh to be called.

                  还要确保您的 FirebaseInstanceIdService 在您的 AndroidManifest.xml 中正确定义

                  Also be sure that your FirebaseInstanceIdService is properly defined in your AndroidManifest.xml

                  在您的清单文件中.

                   <service
                          android:name="com.bnt.etailers.fcm.MyFireBaseInstanceIDService"
                          android:exported="false">
                          <intent-filter>
                              <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
                          </intent-filter>
                      </service>
                  
                      <service
                          android:name="com.bnt.etailers.fcm.GCMNotificationIntentService"
                          android:exported="false">
                          <intent-filter>
                              <action android:name="com.google.firebase.MESSAGING_EVENT" />
                          </intent-filter>
                      </service>
                  

                  FirebaseInstanceIdService 类

                  FirebaseInstanceIdService class

                  public class MyFireBaseInstanceIDService extends FirebaseInstanceIdService {
                  
                  
                  private static final String TAG = MyFireBaseInstanceIDService.class.getSimpleName();
                  
                  @Override
                  public void onTokenRefresh() {
                      // Get updated InstanceID token.
                      String refreshedToken = FirebaseInstanceId.getInstance().getToken();
                      Log.d(TAG, "Refreshed token: " + refreshedToken);
                  
                      if (refreshedToken!=null) {
                          SettingPreferences.setStringValueInPref(this, SettingPreferences.REG_ID, refreshedToken);
                      }
                      // TODO: Implement this method to send any registration to your app's servers.
                      sendRegistrationToServer(refreshedToken);
                  }
                  // [END refresh_token]
                  
                  /**
                   * Persist token to third-party servers.
                   *
                   * Modify this method to associate the user's FCM InstanceID token with any server-side account
                   * maintained by your application.
                   *
                   * @param token The new token.
                   */
                  private void sendRegistrationToServer(String token) {
                      // Add custom implementation, as needed.
                  }}
                  

                  FirebaseMessagingService 类.

                  FirebaseMessagingService class.

                  public class GCMNotificationIntentService extends FirebaseMessagingService {
                  // Sets an ID for the notification, so it can be updated
                  
                  
                  public GCMNotificationIntentService() {
                      super();
                  }
                  
                  
                  @Override
                  public void onMessageReceived(RemoteMessage message) {
                  
                  }}
                  

                  这篇关于Firebase onTokenRefresh() 未被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在 FCM 中单击通知时打开特定的 Activity 下一篇:Firebase 云消息发送 click_action

                  相关文章

                    <bdo id='zGxfg'></bdo><ul id='zGxfg'></ul>
                  <legend id='zGxfg'><style id='zGxfg'><dir id='zGxfg'><q id='zGxfg'></q></dir></style></legend>

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

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