1

I want to send push notifications using Firebase Cloud Messaging to users of my App. I have two categories:

  1. Country 1
  2. Country 2

In the settings of the app, users have radio buttons to subscribe to either Country 1 or Country 2. I already completed the steps described at https://firebase.google.com/docs/cloud-messaging/android/client and when I use FirebaseInstanceId.getInstance().getToken(), I am obtaining the device token successfully. I was able to send notifications to single devices by using the compose message section of the Firebase console. The Firebase console has three radio buttons:

1) User segment 2) Topic 3) Single device

I understand how to send messages to single devices by using the device token. Now I am trying to fully understand the difference between "topic messages", "target messages", and "user segments". I was reading at https://firebase.google.com/docs/cloud-messaging/android/topic-messaging the following information:

Topic messages are optimized for throughput rather than latency. For fast, secure delivery to single devices or small groups of devices, target messages to registration tokens, not topics.

For what I need, I think using "topic messages" would be convenient, where I would have two topics: "Country 1" and "Country 2", and users decide to subscribe to the country they want to receive promotions from in this case.

"User segments" means that I take a group of device tokens and add them to a segment, and then I broadcast a push notification to that segment, correct? In the case of "topic messages", I would let users to subscribe to the country they want, and in my code I would have something such as the following lines to let someone subscribe to a specific country, correct?:

FirebaseMessaging.getInstance().subscribeToTopic("country1");
FirebaseMessaging.getInstance().subscribeToTopic("country2");

Similarly, I would simply use unsubscribeFromTopic("country1") and unsubscribeFromTopic("country2") for unsubscribing users from topics.

I would appreciate if you could help by letting me know if my statements are correct or if you see that I am misunderstanding the conceptual differences between "topic messages", "target messages", and "user segments". Thank you.

Jaime Montoya
  • 6,915
  • 14
  • 67
  • 103

2 Answers2

1

The conceptual answer that I was looking for is at https://firebase.google.com/docs/cloud-messaging/android/send-multiple

Send Messages to Multiple Devices: Firebase Cloud Messaging provides two ways to target a message to multiple devices: Topic messaging, which allows you to send a message to multiple devices that have opted in to a particular topic. Device group messaging, which allows you to send a message to multiple devices that belong to a group you define.

Jaime Montoya
  • 6,915
  • 14
  • 67
  • 103
  • 1
    [Device Group Messaging on Android](https://firebase.google.com/docs/cloud-messaging/android/device-group) "Typically, "group" refers a set of different devices that belong to a single user." ? – Vassilis May 31 '18 at 12:34
0

read this for your app's security....

Topic messaging allows any app client to subscribe to the topic. Not so good for security as anyone can subscribe to. more reference here

Device groups are good as you define the security features of the group if anyone can access them or only a specified number of people can access the feature. more reference here

emanuel sanga
  • 815
  • 13
  • 17