I'm working on an Android SDK that uses Firebase Cloud Messaging to receive push notifications from my backend. The SDK should work correctly whether the host app is also using Firebase or not. 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.
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.
In the source code for the FirebaseMessaging
class, there is a package-private initializer that takes in a 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.
What is the current recommended approach for using FCM with multiple Firebase projects in the same app?