0

I'm integrating to my project a piece of code that is using the deprecated interface FirebaseInstanceId instead of FirebaseMessaging and FirebaseInstallations to register and receive incoming calls.

As I am new to Firebase, I don't fully understand the original code and I'm unsure how to change it in order to achieve the desired outcome.

I wasn't able to fully improve my understanding and find a solution when looking at these posts:

Looking at the Firebase documentation, my basic understanding is that:

  1. FirebaseInstanceId.getInstance() we are returning an instance of the class
  2. .getInstanceId() to then returns a Task
  3. .addOnSuccessListener(this, instance -> ...) that then calls a method if it is succesful
  4. fcmToken = instanceIdResult.getToken() which gets a FCM Token

However, I'm not exactly sure if this is correct nor am I clear on what exactly the instanceIdResult and Task represent here.

Code

/* Register your FCM token to receive incoming call invites */
private void registerForCallInvites() {
   FirebaseInstanceId.getInstance().getInstanceId().addOnSuccessListener(this, instanceIdResult -> {
            String fcmToken = instanceIdResult.getToken();
            Log.i(TAG, "Registering with FCM");
            Voice.register(accessToken, Voice.RegistrationChannel.FCM, fcmToken, registrationListener);
        });
}

How does this code actually work and how would I go about rewriting it to make it compile?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
D-I-S-C
  • 79
  • 1
  • 6

1 Answers1

-1

Referred to the deprecated FirebaseInstanceId, use FirebaseMessaging:

FirebaseInstanceId.Instance.Token -> (string)FirebaseMessaging.Instance.GetToken()

Please refer to this link: https://gist.github.com/jfversluis/dd760594099066c7450d50cce6499368?permalink_comment_id=4485646#gistcomment-4485646

Javier
  • 59
  • 1
  • 3