简体   繁体   English

在同一个 Android 应用程序中使用多个 Firebase 项目的 Firebase 云消息传递的当前最佳实践是什么?

[英]What is the current best practice for using Firebase Cloud Messaging with multiple Firebase projects in the same Android app?

I'm working on an Android SDK that uses Firebase Cloud Messaging to receive push notifications from my backend.我正在开发一个 Android SDK,它使用 Firebase Cloud Messaging 从我的后端接收推送通知。 The SDK should work correctly whether the host app is also using Firebase or not.无论主机应用程序是否也在使用 Firebase,SDK 应该都能正常工作。 The FCM documentation outlines an approach for allowing multiple senders to send push notifications to the same app, however the wording is cryptic and there don't appear to be any code samples for how to do this. FCM 文档概述了一种允许多个发件人向同一个应用程序发送推送通知的方法,但措辞含糊不清,似乎没有任何代码示例说明如何执行此操作。

After digging around, it looks like there used to be (circa 2018) a way of accomplishing this by calling FirebaseInstanceId.getInstance().getToken("senderId1,senderId2", FirebaseMessaging.INSTANCE_ID_SCOPE) , which is now deprecated.在四处挖掘之后,看起来曾经(大约 2018 年)通过调用FirebaseInstanceId.getInstance().getToken("senderId1,senderId2", FirebaseMessaging.INSTANCE_ID_SCOPE)来完成此任务,现在已弃用。

In the source code for the FirebaseMessaging class, there is a package-private initializer that takes in a FirebaseApp object.FirebaseMessaging class 的源代码中,有一个包私有初始化程序接受FirebaseApp object。 This looks like it should be the correct way of generating FCM registration tokens for secondary Firebase apps, and indeed if I use reflection to access this initializer method and generate tokens using FirebaseMessaging.getInstance(**secondaryApp**).getToken().addOnCompleteListener(...) I am able to send push notifications successfully, however this is a subpar solution for obvious reasons.这看起来应该是为辅助 Firebase 应用程序生成 FCM 注册令牌的正确方法,实际上,如果我使用反射来访问此初始化程序方法并使用FirebaseMessaging.getInstance(**secondaryApp**).getToken().addOnCompleteListener(...)我能够成功发送推送通知,但是由于显而易见的原因,这是一个低于标准的解决方案。

What is the current recommended approach for using FCM with multiple Firebase projects in the same app?在同一个应用程序中将 FCM 与多个 Firebase 项目一起使用的当前推荐方法是什么?

The fact that FirebaseMessaging does not expose a public method for getInstance(app) suggests that initialization with multiple projects are not supported for FCM. FirebaseMessaging 没有公开getInstance(app)的公共方法这一事实表明,FCM 不支持使用多个项目进行初始化。 You will notice that the same is true for FirebaseAnalytics , FirebaseCrashlytics and FirebaseInAppMessaging .您会注意到FirebaseAnalyticsFirebaseCrashlyticsFirebaseInAppMessaging也是如此。 These products all rely on Android singleton services that must be registered in the app manifest, which can't be changed before launch.这些产品都依赖于 Android singleton 服务,这些服务必须在应用清单中注册,在发布前无法更改。 This is why they only support a single (default) FirebaseApp instance.这就是为什么它们只支持单个(默认) FirebaseApp实例。

You can initialize as many FirebaseApp instances you want, one for each project you want to use, but these specific products can only work with the default app.您可以初始化任意数量的 FirebaseApp 实例,为您要使用的每个项目创建一个实例,但这些特定产品只能与默认应用一起使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用XMPP服务器和Google云消息传递(或更新的Firebase云消息传递)进行推送通知的Android应用程序App - Chat App for Android using a XMPP Server and Google Cloud Messaging (or the newer Firebase Cloud Messaging) for Push Notifications 使用Firebase云消息传递的通知 - Notification using Firebase cloud Messaging Firebase云消息传递-未收到任何消息(Android) - Firebase Cloud Messaging - Not receiving any messages (Android) 具有Android Java中的Google Cloud Messaging的Firebase - Firebase with Google Cloud Messaging in Android Java 如何在单个 Android 应用程序中同时使用两个 firebase 项目? - How to use two firebase projects in single Android app at same time? 如何使用Firebase Cloud Messaging根据Firebase数据发送通知 - How to send notifications depending on the Firebase data using Firebase Cloud Messaging 聊天消息传递应用程序崩溃(使用Firebase) - Chat messaging app crashes (using Firebase) 将JSON发送到Firebase Cloud Messaging - Sending JSON to Firebase Cloud Messaging Firebase 云消息传递 - onMessageReceived 不起作用 - Firebase Cloud Messaging - onMessageReceived not working Android推送通知未使用Firebase云消息传递或任何其他类似服务 - Android Push Notifications Without using Firebase Cloud Messaging or any other similar service
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM