Find a way to make it work with multiple FCM projects.
download the google-services.json (but dont added to the app project).
Also see https://github.com/firebase/firebase-android-sdk/issues/4316
Using the info from it to construct the non-default FairebaseApp (appKey needs to get from the FCM project), and from FirebaseApp it can get the pushtoken for the FCM project (if the app is just receiving the push only it actually does not need the pushtoken but only to FirebaseApp.initializeApp
).
fun getSecond_FirebaseApp() {
val fcmAppName = "send-fcmProject"
val devOptions = FirebaseOptions.Builder()
.setProjectId("fcm-project-id")
.setApplicationId("fcm-project-appid")
.setApiKey("fcm-project-apikey")//<==id from FCM project
//.setGcmSenderId("fcm-proj-sender-id")//<==id from FCM project
.build()
FirebaseApp.initializeApp(this, devOptions, fcmAppName)
// the FirebaseApp.getInstance() will return deafult FirebaseApp which is instantiated by the FCM sdk automatically, which the app does not need to anything.
val app = FirebaseApp.getInstance(fcmAppName)
val firebaseMessaging = app.get(FirebaseMessaging::class.java) as FirebaseMessaging
android.util.Log.d(
"+++",
"+++ FirebaseApp($fcmAppName); app.isDefaultApp: ${app.isDefaultApp}\n" +
"app.name: ${app.name}\n" +
"app.options.applicationId: ${app.options.applicationId}\n" +
"app.options.apiKey: ${app.options.apiKey}\n" +
"app.options.projectId: ${app.options.projectId}\n" +
"app.options.gcmSenderId: ${app.options.gcmSenderId}"
)
firebaseMessaging.token.addOnCompleteListener {
if (it.isSuccessful) {
// got the token
}
}
}
after FirebaseApp.initializeApp(this, devOptions, fcmAppName)
the app is able to receive the FCM push sent from the second FCM project in the app's single implemented FirebaseMessagingService::onMessageReceived(RemoteMessage remoteMessage)
.
issue:
The FCM messages are received by the single FirebaseMessagingService::onMessageReceived(RemoteMessage remoteMessage)
, the app has to have a way to dispatch the corresponding message to the related project.
Maybe Firebase SDKs are not intended for library projects. The features available on Firebase were integrated in an application level and not on a per module or per library basis.
Does anyone know if there is documentation for using Firebase SDK in android library?