Home > Net >  How to subscribe to a topic in firebase cloud messaging from device
How to subscribe to a topic in firebase cloud messaging from device

Time:09-24

How do I subscribe to topics on firebase on from a device, Earlier it used to be as simple as

 FirebaseMessaging.getInstance().subscribeToTopic(topic)
        .addOnCompleteListener { task ->
}

now the function has changed to

public TopicManagementResponse subscribeToTopic(@NonNull List<String> registrationTokens,
      @NonNull String topic) throws FirebaseMessagingException {
    return subscribeOp(registrationTokens, topic).call();
  }

where there is an extra param with registration tokens... How do I subscribe to a topic from a device with the latest code ??

CodePudding user response:

You seem to be using the Admin SDK for server-side Java code. This SDK should only be used in trusted environments, such as your development machine, a server you control, or Cloud Functions. Using the Admin SDK in your client-side Android code is a security risk, as it allows malicious users to get administrative access to your Firebase project.

The solution is to follow the documentation for Android developers on subscribing to a topic. When you do that, the code should look like this:

FirebaseMessaging.getInstance().subscribeToTopic("weather")
  • Related