Home » Android » android – Count subscribers of a topic in Firebase Cloud Messaging

android – Count subscribers of a topic in Firebase Cloud Messaging

Posted by: admin June 15, 2020 Leave a comment

Questions:

What I want to do with my app is this: users can select different interests and as soon as there are more than ~5 people interested in the same thing, I want to send them a notification.

I thought Firebase + Topics would be a good choice for this.

But how do I find out how many people have subscribed to a topic?

How to&Answers:

There is no available API to check how many subscribers a topic has. (see my answer here)

You’ll have to implement the mapping on your server-side, saving the name of the topics and adding in the list of subscribers. Upon subscription, add the new subscriber, check the count (see if it’s within your preferred number), then trigger a notification.

Answer:

There is no direct way of doing this. Your only two options are:

  1. Using stored deviceIDs in your own DB, manually script to retrieve each users subscriptions.
  2. Already track in your own DB each users deviceIDs AND every topic they subscribe to.

There are so many problems with both of these methods though. It’s frustrating topic managmenet doesn’t already exist in FCM Console. I wrote Google a feature request for FCM Cloud Notification Topic Management and this is the response I got:

We’re aware that many developers, such as yourself, would like to have
this topic management. There’s actually an existing feature request
regarding this. However, I can’t provide any details or timelines as
to when this will be available.