用于辅助应用程序的FirebaseMessaging.getInstance(firebaseApp)应该是公共的,但它是私有的? [英] FirebaseMessaging.getInstance(firebaseApp) for secondary app supposed to be public but it's private?
问题描述
我正在尝试为辅助Firebase应用程序订阅FCM(Firebase云消息传递)主题,根据文档,这可以由重载的getInstance
完成,该重载将辅助FirebaseApp实例作为参数:>
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:
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 FirebaseApp
s.
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屋!