I'm trying to receive messages from multiple Firebase projects(senders) using the pointers in this post. I have initialized the FirebaseApp with appropriate options and have called getToken()
on each of the senders/projects. But this doesn't work. The only FCM messages that I receive are from the project whose google-services.json has been included in the project. Please let me know if I am missing something here. Thanks.
FirebaseApp.initializeApp(context);
FirebaseOptions options1 = new FirebaseOptions.Builder()
.setApiKey("apiKey1")
.setApplicationId("appId1")
.setGcmSenderId("senderId1")
.setStorageBucket("bucket1")
.setDatabaseUrl("database1")
.build();
FirebaseApp.initializeApp(context, options1, "project1");
FirebaseOptions options2 = new FirebaseOptions.Builder()
.setApiKey("apikey2")
.setApplicationId("appId2")
.setGcmSenderId("sender2")
.setStorageBucket("bucket2")
.setDatabaseUrl("database2")
.build();
FirebaseApp.initializeApp(context, options2, "project2");
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
try {
String token1 = FirebaseInstanceId.getInstance(FirebaseApp.getInstance("project1")).getToken("sender1", FirebaseMessaging.INSTANCE_ID_SCOPE);
String token2 = FirebaseInstanceId.getInstance(FirebaseApp.getInstance("project2")).getToken("sender2", FirebaseMessaging.INSTANCE_ID_SCOPE);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void result) {
}
}.execute();
FirebaseMessaging fcm = FirebaseMessaging.getInstance();