Farzad
Farzad

Reputation: 2099

Android firebase true way for subscribe to multiple topics

How to subscribe to multiple topics?

for loop example in my android app:

foreach (String[] all_following_topics_from_user: String topic_name) {
     FirebaseMessaging.getInstance().subscribeToTopic(topic_name);
}

// example:
FirebaseMessaging.getInstance().subscribeToTopic("topic_name_1");
FirebaseMessaging.getInstance().subscribeToTopic("topic_name_2");
FirebaseMessaging.getInstance().subscribeToTopic("topic_name_3");
.
.
.
FirebaseMessaging.getInstance().subscribeToTopic("topic_name_589");
FirebaseMessaging.getInstance().subscribeToTopic("topic_name_590");

Is true way subscribe to all by loop? or exists another way?

Upvotes: 3

Views: 2408

Answers (1)

AL.
AL.

Reputation: 37798

Yes. There is currently no other method to subscribe to a topic via the Android client other than the subscribeToTopic() method. Another way would be to handle the relationships on your server using the InstanceID API:

Create a relation mapping for an app instance

Given a registration token and a supported relationship, you can create a mapping. For example, you can subscribe an app instance to a Google Cloud Messaging topic by calling the Instance ID service at this endpoint, providing the app instance's token as shown:

https://iid.googleapis.com/iid/v1/IID_TOKEN/rel/topics/TOPIC_NAME

Noting that you would still need to loop from here.

Upvotes: 4

Related Questions