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
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.
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.
For Android, you can send up to 240 messages/minute and 5,000 messages/hour to a single device.
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.
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");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With