How do I make Firebase Cloud Messaging send a message to a specific user?

Asked

Viewed 207 times

-2

I’m trying to get Firebase Cloud Messaging to send a message to a specific user but I’m not getting... First I am registering the device and saving the id on my server:

FirebaseInstanceId.getInstance().getInstanceId()
    .addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() {
        @Override
        public void onComplete(@NonNull Task<InstanceIdResult> task) {
            if (!task.isSuccessful()) {
                Log.w(TAG, "getInstanceId failed", task.getException());
                return;
            }

            // Pega o ID token
            String token = task.getResult().getToken();
            // depois envia para o servidor
            saveToken(token);


        }
    });

So I try to send my message through the back-end to:

https://fcm.googleapis.com/fcm/send

With the id that was registered in the database

As in this example tutorial:

http://ricardolecheta.com.br/? p=894

2 answers

0

Sending to a specific user is done via the firebase console by inserting the firebase token from the device or setting up a server to send to that specific token.

Clicking here

0

First check if the token is saving on your server, Test in Postman with the token you pick up on Android and see if Success, why if you did not put google-services.json correctly does not generate the right token

Do not forget to include in the push service manifest.xml

  <service android:name=".MyFirebaseMessagingService">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT"/>
        </intent-filter>
    </service>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.