According to Firebase cloud messaging documentation, for subscribing a user to a topic I need to call
FirebaseMessaging.getInstance().subscribeToTopic("news");
- In my application, I need all users to be subscribed to my cloud
messaging topic. Since return value is
void
, the question is how can I understand that subscription was successful? - Is it a bad practice to call
subscribeToTopic
each time my application starts?
Edit:
You could now check if subscription is successful by adding
addOnSuccessListener()
Original:
There is nothing explicitly mentioned in the docs about a response received when the subscription is successful.However, if you need to mandate all of your users to be subscribed to a specific topic, you should call the
subscribeToTopic
on your app's first install. This will most likely make sure that there is a connection to the internet (since it's probably been downloaded and installed via the Play Store) and the subscription successful.However, if you want to make sure, you can also handle he checking via your own App Server. As mentioned in the docs:
Check through the registration tokens, if they haven't been successfully subsribed to your topic, send a notification to it where it will trigger your client app to call
subscribeToTopic
.Edit: Adding it in from the comments section: Subscribing on app start should be fine.
Thank you @FrankvanPuffelen for verifying. :)