Fcm (Firebase Cloud Messaging) Send to Multiple Devices

FCM Send message to multiple devices - which way to use?

You probably want to use multicast if you're targeting an individual user's specific devices. You probably don't want to use device groups. I suggest reading the documentation to understand how device groups work:

Device group messaging allows you to add multiple devices to a single group. This is similar to topic messaging, but includes authentication to ensure that group membership is managed only by your servers. For example, if you want to send different messages to different phone models, your servers can add/remove registrations to the appropriate groups and send the appropriate message to each group. Device group messaging differs from topic messaging in that it involves managing device groups from your servers instead of directly within your application.

Device groups are basically just topics whose membership is fully managed by your server code, not by client code.

FCM, send multiple devices without tokens?

There is no "send to all users" operation in FCM. You either will have to send to each token (that's not a heave operation for FCM, which handles billions of such calls every second), or you have to subscribe all instances to a specific topic and then send to that topics (which ends up the same behind the scenes, just with Firebase loading the tokens for the topic for you).

This has been covered a few times before, so I recommend checking:

  • How do you send a Firebase Notification to all devices via CURL?
  • How to send notifications to all devices using Firebase Cloud Messaging
  • Firebase Cloud Messaging - Send message to all users

The notifications panel in the Firebase console has an option to deliver messages at a specific time, but no such option exists in the Firebase Cloud Messaging API. You'll have to either implement your own mechanism to schedule the delivery, or you can deliver a data message right away and then only display the notification on the device when it's time.

This also has been covered a few times before, so check:

  • Firebase Messaging FCM Distribution over configurable time interval
  • How can scheduled Firebase Cloud Messaging notifications be made outside of the Firebase Console?
  • Flutter Firebase Messaging: How to send push notifications to users at specified time

FCM (Firebase Cloud Messaging) Send to multiple devices

Update: For v1, it seems that registration_ids is no longer supported. It is strongly suggested that topics be used instead. Only the parameters shown in the documentation are supported for v1.


Simply use the registration_ids parameter instead of to in your payload. Depending also on your use case, you may use either Topic Messaging or Device Group Messaging.

Topic Messaging

Firebase Cloud Messaging (FCM) topic messaging allows you to send a message to multiple devices that have opted in to a particular topic. Based on the publish/subscribe model, topic messaging supports unlimited subscriptions for each app. You compose topic messages as needed, and Firebase handles message routing and delivering the message reliably to the right devices.

For example, users of a local weather forecasting app could opt in to a "severe weather alerts" topic and receive notifications of storms threatening specified areas. Users of a sports app could subscribe to automatic updates in live game scores for their favorite teams. Developers can choose any topic name that matches the regular expression: "/topics/[a-zA-Z0-9-_.~%]+".



Device Group Messaging

With device group messaging, app servers can send a single message to multiple instances of an app running on devices belonging to a group. Typically, "group" refers a set of different devices that belong to a single user. All devices in a group share a common notification key, which is the token that FCM uses to fan out messages to all devices in the group.

Device group messaging makes it possible for every app instance in a group to reflect the latest messaging state. In addition to sending messages downstream to a notification key, you can enable devices to send upstream messages to a device group. You can use device group messaging with either the XMPP or HTTP connection server. The limit on data payload is 2KB when sending to iOS devices, and 4KB for other platforms.

The maximum number of members allowed for a notification_key is 20.


For more details, you can check out the Sending to Multiple Devices in FCM docs.

send cloud message (FCM) multiple devices single user

You need to change your DB and add ability to save all device tokens from one user. Then you need to call this Firebase api https://fcm.googleapis.com/fcm/send as many times as the tokens user have. Here the official documentation.

https://firebase.google.com/docs/cloud-messaging/http-server-ref

To update device specific token when it is changed on client side, you also have to bound that token with the deviceID, so to have that you need to pass the DeviceId to the server when passing the Firebase token. As deviceID can serve Android unique deviceID, or the id that provides Firebase in client side FirebaseInstanceId.getInstance().id. And here how to get Android deviceID

Is there a unique Android device ID?

If you use access_token for login the user, as another alternative, you can bound firebase token with user access_token, as it is unique for any device the user logged in.

Firebase cloud messaging multiple devices and a single account

Firebase Cloud Messaging only knows about app instances, a single app installed on a single device.

If your app associated that with users, the logic of how to do so is application specific. If you want to alert the user on all their devices, you'll want to store multiple tokens per user. If you want to only alert the user on their active or most recently active device, you'll only want to store a single token per user. All these scenarios are possible, but you'll have to implement as part of your application logic.

Also see:

  • When to register an FCM token for a user
  • How to handle multiple Firebase FCM tokens per user?
  • Receiving the same token for different users when using firebase messaging
  • Is FCM (firebase cloud messaging) Token for one device or for one account?


Related Topics



Leave a reply



Submit