Receive Push Notifications on One Android App from Two Firebase Projects

Receive push notifications on one android app from two Firebase projects

There is actually a part in the documentation about this topic:

Receiving messages from multiple senders

FCM allows multiple parties to send messages to the same client app. For example, suppose the client app is an article aggregator with multiple contributors, and each of them should be able to send a message when they publish a new article. This message might contain a URL so that the client app can download the article. Instead of having to centralize all sending activity in one location, FCM gives you the ability to let each of these contributors send its own messages.

To make this possible, make sure each sender generates its own sender ID. See the client documentation for your platform for information on on how to obtain the FCM sender ID. When requesting registration, the client app fetches the token multiple times, each time with a different sender ID in audience field.

Finally, share the registration token with the corresponding app servers (to complete the FCM registration client/server handshake), and they'll be able to send messages to the client app using their own authentication keys.

Note that there is limit of 100 multiple senders.

I think the confusing but important part here is:

When requesting registration, the client app fetches the token multiple times, each time with a different sender ID in audience field.

In other terms, you'll have to call getToken() passing the Sender ID and simply "FCM" (e.g. getToken("2xxxxx3344", "FCM")) as the parameters. You'll have to make sure that you call this for each sender (project) that you need.

Also, note from the getToken() docs:

This is a blocking function so do not call it on the main thread.

Some additional good-to-knows:

  • It does not auto retry if it fails like the default one.
  • It returns an IOException when it fails.

How to send a notification to Android app A from app B? The firebase project connections of these two apps are different

You can add multiple apps to one Firebase project:

You can add app B to Firebase project A and use project A for FCM messages.

Look here :

https://firebase.google.com/docs/projects/multiprojects

Should i use multiple firebase projects for different customers but the same app or only one for FCM?

They should not be allowed to see any data of other customers or send messages to them.

If you require isolation between customers, then they should definitely not be using the same project. They should be in different projects, so they can't send messages outside of their own user base.

Firebase - Can multiple apps within the same project use the same service account key (push notifications)

You only need one service account configured per project. It doesn't matter how many apps you have added to that project - you will be able to send messages to any of the devices where any of those apps are installed.

It's up to you to collect the device tokens and make sure you are targeting the correct devices with each push. You might need to create some way to discern which tokens came from which apps, if that matters for your push.

How to send notifications to one of two apps in the same project at firebase

after a lot of search i didn't got an answer from firebase side to differentiate between 2 apps
so i just made a condition into background message service and know if the app is develop or master version and then push the notification if it's my correct version



Related Topics



Leave a reply



Submit