Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to subscribe to multiple topics in FCM?

Hi everyone i'm newly learning android studio,so however i have one doubt in developing a android app that,How can we subscribe to multiple topics in FCM,Here is my code

public void subscribeToPushService() {
        FirebaseMessaging.getInstance().subscribeToTopic("News");

        Log.d("myname", "Subscribed");
        // Toast.makeText(Simple.this, "Subscribed", Toast.LENGTH_SHORT).show();

        String token = FirebaseInstanceId.getInstance().getToken();

        // Log and toast
        Log.d("myname", token);
        // Toast.makeText(Simple.this, token, Toast.LENGTH_SHORT).show();
    }

you can see in the above code i have already subscribed to one topic "News" so how can i subscribe to multiple topics instead of one. is it possible ,if yes how can we do that.

Thanks in advance

like image 415
GOPALA KRISHNA REDDY KOVVURI Avatar asked Mar 17 '17 16:03

GOPALA KRISHNA REDDY KOVVURI


People also ask

How many topics can be created in FCM?

However, FCM enforces limits in these areas: One app instance can be subscribed to no more than 2000 topics. If you are using batch import to subscribe app instances, each request is limited to 1000 app instances.

How do I send FCM notifications 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.

Is there any limit for FCM?

For Android, you can send up to 240 messages/minute and 5,000 messages/hour to a single device.

How do I subscribe to a topic in Firebase console?

Send to a topicFrom Firebase console Notification section, click New Message. Enter the text of your message in the Message Text field. Click on the SUBSCRIBE TO NEWS button to subscribe to the news topic. Set the target to Topic.


1 Answers

Yes,find below sample code for subscribe multiple topics

public void subscribeToPushService() {
        FirebaseMessaging.getInstance().subscribeToTopic("News");
        FirebaseMessaging.getInstance().subscribeToTopic("Movies");
        FirebaseMessaging.getInstance().subscribeToTopic("etc");
}

For unsubscribe topic

FirebaseMessaging.getInstance().unsubscribeFromTopic("Topic name");
like image 129
Kanaiya Katarmal Avatar answered Sep 29 '22 13:09

Kanaiya Katarmal