用于辅助应用程序的FirebaseMessaging.getInstance(firebaseApp)应该是公共的,但它是私有的? [英] FirebaseMessaging.getInstance(firebaseApp) for secondary app supposed to be public but it's private?

查看:394
本文介绍了用于辅助应用程序的FirebaseMessaging.getInstance(firebaseApp)应该是公共的,但它是私有的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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)
 

获取指定FirebaseApp的FirebaseMessaging实例.

我正在使用Kotlin,并且像这样在build.gradle中提取软件包:

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

但是当我尝试使用重载的getInstance实例化FirebaseMessaging时,我收到一条错误消息,指出它不可访问.当我查看软件包源代码时,反编译表明重载的构造函数不像无参数的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);
    }
 

我错过了什么吗?

解决方案

可以 val senderId = getSenderIdFromServer() val token = FirebaseInstanceId.getInstance().getToken(senderId, "FCM") sendTokenToServer(token)

警告:FirebaseInstanceId.getToken现在已被弃用,我在SDK中看不到任何替代物.

虽然看起来不可能从其他项目接收主题消息.当前,新的服务器SDK缺少无法发送到设备的功能组.

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?

解决方案

It is possible to receive messages from multiple senders using a different approach than instantiating multiple FirebaseApps.

You can get the Sender ID of the other project under Settings -> Cloud Messaging in Firebase Console and use it on the client to this end.

Sender ID is also what you will receive as RemoteMessage.getFrom() in FirebaseMessagingService.onMessageReceived(RemoteMessage).

In your client app, you will have to retrieve a token for that sender, to authenticate receiving messages from the other project. Then use that token in the backend as the target of the push message.

val senderId = getSenderIdFromServer()

val token = FirebaseInstanceId.getInstance().getToken(senderId, "FCM")

sendTokenToServer(token)

Warning: FirebaseInstanceId.getToken is now deprecated and there is no replacement that I see in the SDK.

Looks like it's not possible to receive topic messages from a different project though. And currently the new server SDK lacks the ability to send to a device group.

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

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆