I want to be able to add more than one sender id in my android app.
From https://developers.google.com/cloud-messaging/concept-options
GCM allows multiple parties to send messages to the same client app. For example, suppose the client app is an articles 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, GCM gives you the ability to let each of these contributors send its own messages.
How is this achieved using google-services.json
configuration file?
As of Dec. 2016, there's a very simple, non-hacky way to do this, which still works now (Jul 2018).
Source: The official Firebase blog
You can get the single token for multiple sender by passing them as comma separated string and then these sender will be able to send the push notification using the common token, try calling
make sure you call this from a background thread.
UPDATE: Going to refer to the official and recommended way in doing this instead of the hacky and unofficial approach to prevent/avoid unknown problems. From my answer here.
There is actually a part in the documentation about this topic:
I think the confusing but important part here is:
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:Some additional good-to-knows: