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:
- FirebaseInstanceIdService is deprecated
- What method should I use now since FirebaseInstanceId.getInstance().getToken() is deprecated
Looking at the Firebase documentation, my basic understanding is that:
FirebaseInstanceId.getInstance()
we are returning an instance of the class.getInstanceId()
to then returns a Task.addOnSuccessListener(this, instance -> ...)
that then calls a method if it is succesfulfcmToken = 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?