• <bdo id='8wvxZ'></bdo><ul id='8wvxZ'></ul>

        <small id='8wvxZ'></small><noframes id='8wvxZ'>

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

        <tfoot id='8wvxZ'></tfoot>

      1. <legend id='8wvxZ'><style id='8wvxZ'><dir id='8wvxZ'><q id='8wvxZ'></q></dir></style></legend>

        如何生成 Firebase 注册令牌

        时间:2023-07-28

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

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

              <tfoot id='v3Wcp'></tfoot><legend id='v3Wcp'><style id='v3Wcp'><dir id='v3Wcp'><q id='v3Wcp'></q></dir></style></legend>

                • <bdo id='v3Wcp'></bdo><ul id='v3Wcp'></ul>
                    <tbody id='v3Wcp'></tbody>
                • 本文介绍了如何生成 Firebase 注册令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试使用新方法生成 Firebase 注册令牌,但无法生成这是我的以下代码:

                  I am trying to generate firebase registration token with new method but unable to generate this is my code below:

                  MyFirebaseInstanceIdService.java

                  public class MyFirebaseInstanceIdService extends FirebaseMessagingService {
                  
                  @Override
                  public void onNewToken(String s) {
                      super.onNewToken(s);
                  
                      FirebaseInstanceId.getInstance().getInstanceId().addOnSuccessListener(new OnSuccessListener<InstanceIdResult>() {
                          @Override
                          public void onSuccess(InstanceIdResult instanceIdResult) {
                  
                              String token = instanceIdResult.getToken();
                              Log.d("Token",token);
                          }
                      });
                    }
                  }
                  

                  Manifest.xml

                  <manifest xmlns:android="http://schemas.android.com/apk/res/android"
                  xmlns:dist="http://schemas.android.com/apk/distribution"
                  package="com.app.retrofitapp">
                  
                  <dist:module dist:instant="true" />
                  
                  <uses-permission android:name="android.permission.INTERNET" />
                  
                  <application
                      android:allowBackup="true"
                      android:icon="@mipmap/ic_launcher"
                      android:label="@string/app_name"
                      android:roundIcon="@mipmap/ic_launcher_round"
                      android:supportsRtl="true"
                      android:theme="@style/AppTheme">
                  
                      <activity android:name=".Users"></activity>
                  
                      <activity android:name=".MainActivity">
                          <intent-filter>
                              <action android:name="android.intent.action.MAIN" />
                  
                              <category android:name="android.intent.category.LAUNCHER" />
                          </intent-filter>
                      </activity>
                  
                      <service android:name=".MyFirebaseInstanceIdService">
                      <intent-filter>
                          <action android:name="com.google.firebase.MESSAGING_EVENT"></action>
                      </intent-filter>
                      </service>
                  
                  </application>
                  

                  使用上述方法在 log cat 中没有显示任何令牌.请有人告诉我我做错了什么.任何帮助将不胜感激.

                  There is no token is showing in log cat with above method.Someone please let me know what I am doing wrong.Any help would be appreciated.

                  谢谢

                  推荐答案

                  如果您只想要 fcm 令牌(不关心通知),您只需要清单中的以下服务和操作 INSTANCE_ID_EVENT...

                  If you want just fcm token(not bother about notification) you only need below service in manifest with action INSTANCE_ID_EVENT...

                  <service android:name=".fcm.FireBaseInstanceIdService">
                      <intent-filter>
                          <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
                      </intent-filter>
                  </service>
                  

                  然后在您的活动中添加以下代码(onCreate 会很好)

                  And after this add the below code in your activity (onCreate will be good)

                  FirebaseInstanceId.getInstance().getInstanceId()
                                  .addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() {
                                      @Override
                                      public void onComplete(@NonNull Task<InstanceIdResult> task) {
                                          if (!task.isSuccessful()) {
                                              Log.w(TAG, "Failed", task.getException());
                                              return;
                                          }
                  
                                          String token = task.getResult().getToken();
                                          Log.i("FCM", "Current token=" + token);
                                      }
                                  });
                  

                  您将在那里获得您当前的令牌.希望它会有所帮助.

                  You will get your current token there. Hope it will help.

                  这篇关于如何生成 Firebase 注册令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:当应用程序在后台时,FCM 无法显示弹出窗口 下一篇:应用程序处于非活动状态时未调用 Firebase onMessageReceived

                  相关文章

                    • <bdo id='NIU0o'></bdo><ul id='NIU0o'></ul>
                  1. <legend id='NIU0o'><style id='NIU0o'><dir id='NIU0o'><q id='NIU0o'></q></dir></style></legend>

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

                    <tfoot id='NIU0o'></tfoot>