How to subscribe to a topic in firebase cloud messaging from device

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

        .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 ??

1 answer

  • answered 2021-09-23 15:00 Frank van Puffelen

    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:


How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum