0

I want to subscribe to a topic in FCM to send notification to multiple user at the same time and I have all the users in the list and list contains the token. so my question is that how can list of user subscribe to a topic.thanks

MMG
  • 3,226
  • 5
  • 16
  • 43
  • You can look at the [docs](https://firebase.google.com/docs/cloud-messaging/android/topic-messaging#subscribe_and_unsubscribe_using_the) – Kasım Özdemir Apr 30 '20 at 18:13
  • TopicManagementResponse response = FirebaseMessaging.getInstance().subscribeToTopic( registrationTokens, topic); sir when i add registrationTokens list in this it ask me to add only string – Zahid Iqbal Apr 30 '20 at 18:19
  • required: String found: List,String it shows this previous error – Zahid Iqbal Apr 30 '20 at 18:21
  • Client apps can subscribe to any existing topic, or they can create a new topic. You cannot add list with client apps. – Kasım Özdemir Apr 30 '20 at 18:33
  • sir i want to send a notification to multiple users so i choose topic messaging so now please suggest any other method to do this bcz i am sending a proposal that contain 4,5 users so i want to send notification to all users – Zahid Iqbal Apr 30 '20 at 18:37
  • You can subscribe users to a topic with this [method](https://firebase.google.com/docs/cloud-messaging/android/send-multiple#subscribe_the_client_app_to_a_topic). Then you can send notifications to users from the firebase console or your own server. Or you can send requests to fcm servers. – Kasım Özdemir Apr 30 '20 at 18:46

1 Answers1

0

From https://firebase.google.com/docs/cloud-messaging/manage-topics
I assume you're using java for server-side code to manage topics and send cloud messages.

In java, you can do the following to subscribe multiple FCM tokens to a given topic at once.

// These registration tokens come from the client FCM SDKs.
List<String> registrationTokens = Arrays.asList(
    "YOUR_REGISTRATION_TOKEN_1",
    // ...
    "YOUR_REGISTRATION_TOKEN_n"
);

// Subscribe the devices corresponding to the registration tokens to the
// topic.
TopicManagementResponse response = FirebaseMessaging.getInstance().subscribeToTopic(
    registrationTokens, topic);
// See the TopicManagementResponse reference documentation
// for the contents of response.
System.out.println(response.getSuccessCount() + " tokens were subscribed successfully");
deCodeIt
  • 37
  • 1
  • 4