Description
What feature would you like to see?
The Firebase Cloud Messaging 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)
. This would allow for the sender id of the secondary Firebase project to be specified when the token is created, however FirebaseInstanceId
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.
It'd be great to support this method for public use, or at least have more clarity on what the current recommended approach for using FCM with multiple projects in the same app is.
How would you use it?
I am developing an SDK that uses FCM to receive data push notifications from my backend. The SDK should function correctly whether the host app is also using Firebase or not. Currently, when the host app is using Firebase FirebaseMessaging
picks up on the initialization parameters of the host app instead of my SDK. When I attempt to send push notifications from my server to these FCM registration tokens, I get SenderId mismatch
errors (as I would expect if the tokens belong to a different project). If I use reflection to instantiate FirebaseMessaging
with my SDK's FirebaseApp
or if the host app is not using Firebase, I am able to send push notifications successfully.