Lutaaya Huzaifah Idris
Lutaaya Huzaifah Idris

Reputation: 3990

addCompleteListener() is not being resolved - Firebase Cloud Messaging (FCM)

I am wondering why addCompleteListener() is not resolved yet I have provided the necessary dependencies :

classpath 'com.google.gms:google-services:4.2.0'


implementation 'com.google.firebase:firebase-core:16.0.6'
implementation 'com.google.firebase:firebase-iid:17.0.4'
implementation 'com.google.firebase:firebase-messaging:17.3.4'
implementation 'com.firebase:firebase-jobdispatcher:0.8.5'

I followed this question Stackoverflow same question, but I didn't get any luck.

Below is my code,I want to get the device registration token :

FirebaseInstanceId.getInstance().getInstanceId()
                .addCompleteListener(LoginActivity.this,new OnCompleteListener<InstanceIdResult>() {
                    @Override
                    public void onComplete(@NonNull Task<InstanceIdResult> task) {
                        if (!task.isSuccessful()) {
                            return;
                        }
                        String token = task.getResult().getToken();
                        String msg = getString(R.string.fcm_token, token);
                        Log.d("--> FCM Token ", msg);

                    }
                });

Below is the screenshot :

enter image description here

What could lead to this issue ?

Upvotes: 0

Views: 175

Answers (1)

Alex Mamo
Alex Mamo

Reputation: 138824

To solve this, please change the following line of code:

FirebaseInstanceId.getInstance().getInstanceId().addCompleteListener(/* ... */);

to

FirebaseInstanceId.getInstance().getInstanceId().addOnCompleteListener(/* ... */);
//                                                  ^^

There is no addCompleteListener method, it's addOnCompleteListener().

Upvotes: 2

Related Questions