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

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

      <tfoot id='Mz7Kb'></tfoot>

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

        辅助应用程序的 FirebaseMessaging.getInstance(firebaseApp) 应该是公共的,但它

        时间:2023-07-30
        <tfoot id='K1fdn'></tfoot>
            <tbody id='K1fdn'></tbody>
          1. <small id='K1fdn'></small><noframes id='K1fdn'>

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

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

                  <bdo id='K1fdn'></bdo><ul id='K1fdn'></ul>
                  本文介绍了辅助应用程序的 FirebaseMessaging.getInstance(firebaseApp) 应该是公共的,但它是私有的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试为辅助 Firebase 应用订阅 FCM(Firebase 云消息传递)主题,根据文档,这可以通过将辅助 FirebaseApp 实例作为重载的 getInstance 来完成一个参数:

                  https://firebase.google.com/docs/reference/admin/java/reference/com/google/firebase/messaging/FirebaseMessaging#public-static-synchronized-firebasemessaging-getinstance-firebaseapp-应用程序

                  public static synchronized FirebaseMessaging getInstance(FirebaseApp 应用)

                  <块引用>

                  获取指定 FirebaseApp 的 FirebaseMessaging 实例.

                  我正在使用 Kotlin,我正在像这样在 build.gradle 中拉入包:

                  实现com.google.firebase:firebase-messaging:20.2.0"

                  但是当我尝试使用重载的 getInstance 实例化 FirebaseMessaging 时,我收到一条错误消息,指出它不可访问.看包源码,反编译显示,重载的构造函数不像无参的getInstance那样是public的:

                  公共类 FirebaseMessaging {公共静态最终字符串 INSTANCE_ID_SCOPE = "FCM";私有最终上下文 zzb;私有最终 FirebaseInstanceId zzc;私人最终任务<zzab>zd;@Nullable@SuppressLint({"FirebaseUnknownNullness"})@VisibleForTesting静态 TransportFactory zza;@NonNull公共静态同步 FirebaseMessaging getInstance() {返回 getInstance(FirebaseApp.getInstance());}@保持@NonNull静态同步 FirebaseMessaging getInstance(@NonNull FirebaseApp var0) {返回 (FirebaseMessaging)var0.get(FirebaseMessaging.class);}

                  我错过了什么吗?

                  解决方案

                  我已经验证了一种方法,因为我遇到了类似的问题.

                  我使用 google-services.json 文件注册了其中一个项目.

                  现在根据 文档 :

                  <块引用>

                  public void onNewToken(字符串令牌)

                  在为 default Firebase 项目生成新令牌时调用.

                  这里是默认"这个词是至关重要的.它提到重写的 FirebaseMessagingService 中的 onNewToken 方法(例如:MyFirebaseMessagingService)只会为默认项目调用.

                  因此在这种情况下,使用 google-services.json 配置的第一个项目将是默认项目,并且将调用 onNewToken 方法.

                  对于第二个项目,我按照文档:

                  val options = FirebaseOptions.Builder().setProjectId("my-firebase-project").setApplicationId("1:27992087142:android:ce3b6448250083d1").setApiKey("AIzaSyADUe90ULnQDuGShD9W23RDP0xmeDc6Mvw").建造()

                  参数值可以从第二个项目的google-services.json文件中获取.(注意:不要在项目中包含第二个项目的 google-services.json)

                  google-services.json 到手动代码映射

                  1. projectId (setProjectId) : project_id key 在 json 的根目录
                  2. applicationid(setApplicationId): client>客户信息>mobilesdk_app_id.如果有多个项目,请确保使用的客户端是与 Android 应用匹配的 package_name
                  3. apiKey (setApiKey) : client >api_key >current_key(这里也要确保包名.

                  密钥代码

                  在文档中很难找到的最重要部分是获取第二个 firebase 项目的令牌.

                  val app = Firebase.initialize(this, options, "ANY_FIXED_STRING_EXCEPT_DEFAULT")val firebaseMessaging = app.get(FirebaseMessaging::class.java) 作为 FirebaseMessagingymFirebaseMessaging.token.addOnCompleteListener{如果(!it.isSuccessful){Log.d(TAG, "Fetching FCM token failed", it.exception)返回@addOnCompleteListener}val token = it.resultLog.d(TAG, "YM: $token")Toast.makeText(活动,"$TAG: 得到令牌",吐司.LENGTH_LONG).展示()}

                  I'm trying to subscribe to an FCM (Firebase Cloud Messaging) topic for a secondary Firebase App and according to the documentation this could be done by the overloaded getInstance which takes the secondary FirebaseApp instance as a parameter:

                  https://firebase.google.com/docs/reference/admin/java/reference/com/google/firebase/messaging/FirebaseMessaging#public-static-synchronized-firebasemessaging-getinstance-firebaseapp-app

                  public static synchronized FirebaseMessaging getInstance (FirebaseApp app)
                  

                  Gets the FirebaseMessaging instance for the specified FirebaseApp.

                  I'm using Kotlin and I'm pulling in the package in build.gradle like this:

                  implementation "com.google.firebase:firebase-messaging:20.2.0"
                  

                  But when I try to instantiate the FirebaseMessaging with the overloaded getInstance, I get an error stating that it's not accessible. When I look at the package source, the decompilation shows that the overloaded constructor is not public like the parameterless getInstance:

                  public class FirebaseMessaging {
                      public static final String INSTANCE_ID_SCOPE = "FCM";
                      private final Context zzb;
                      private final FirebaseInstanceId zzc;
                      private final Task<zzab> zzd;
                      @Nullable
                      @SuppressLint({"FirebaseUnknownNullness"})
                      @VisibleForTesting
                      static TransportFactory zza;
                  
                      @NonNull
                      public static synchronized FirebaseMessaging getInstance() {
                          return getInstance(FirebaseApp.getInstance());
                      }
                  
                      @Keep
                      @NonNull
                      static synchronized FirebaseMessaging getInstance(@NonNull FirebaseApp var0) {
                          return (FirebaseMessaging)var0.get(FirebaseMessaging.class);
                      }
                  

                  Did I miss something?

                  解决方案

                  I have verified a way to do it as I had been facing a similar issue.

                  I registered one of the projects using the google-services.json file.

                  Now as per the documentation :

                  public void onNewToken (String token)

                  Called when a new token for the default Firebase project is generated.

                  Here the word "default" is of key importance. It mentions that the onNewToken method in the overridden FirebaseMessagingService (eg: MyFirebaseMessagingService) will only be called for the default project.

                  Hence in this case the first project configured using the google-services.json will be the default project and for that the onNewToken method will be called.

                  For the second project, I manually configured the project using the code below following the documentation:

                  val options = FirebaseOptions.Builder()
                          .setProjectId("my-firebase-project")
                          .setApplicationId("1:27992087142:android:ce3b6448250083d1")
                          .setApiKey("AIzaSyADUe90ULnQDuGShD9W23RDP0xmeDc6Mvw")
                          .build()
                  

                  The values for the parameters can be obtained from the google-services.json file of the second project. (NOTE: DON'T INCLUDE THE SECOND PROJECT'S google-services.json IN THE PROJECT)

                  google-services.json to manual code mapping

                  1. projectId (setProjectId) : project_id key in the root of the json
                  2. applicationid (setApplicationId): client > client_info > mobilesdk_app_id. Incase of multiple project make sure that the client used is of the package_name which matches the Android app
                  3. apiKey (setApiKey) : client > api_key > current_key (make sure of the package name here as well.

                  KEY CODE

                  The most important part here which is tough to find in the documentation is to get the token of the second firebase project.

                  val app = Firebase.initialize(this, options, "ANY_FIXED_STRING_EXCEPT_DEFAULT")
                  
                  val firebaseMessaging = app.get(FirebaseMessaging::class.java) as FirebaseMessaging
                  
                  ymFirebaseMessaging.token.addOnCompleteListener{
                                  if (!it.isSuccessful) {
                                      Log.d(TAG, "Fetching FCM token failed", it.exception)
                  
                                      return@addOnCompleteListener
                                  }
                  
                  
                                  val token = it.result
                                  Log.d(TAG, "YM: $token")
                                  Toast.makeText(
                                      activity,
                                      "$TAG: Got token",
                                      Toast.LENGTH_LONG
                                  ).show()
                  }
                  

                  这篇关于辅助应用程序的 FirebaseMessaging.getInstance(firebaseApp) 应该是公共的,但它是私有的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:从 firebase 云消息传递中获取所有订阅的主题 下一篇:计算 Firebase 云消息传递中某个主题的订阅者

                  相关文章

                  • <bdo id='1tla4'></bdo><ul id='1tla4'></ul>

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

                    <small id='1tla4'></small><noframes id='1tla4'>

                  2. <legend id='1tla4'><style id='1tla4'><dir id='1tla4'><q id='1tla4'></q></dir></style></legend>

                      <tfoot id='1tla4'></tfoot>