Firebase instance id: deprecation of getId() in 21.0.0
Fcm Token
Before deprecation
val fcmToken = FirebaseInstanceId.getInstance().getToken()
Replacement
val fcmToken = FirebaseMessaging.getInstance().getToken()
FirebaseInstanceId#getId
Before deprecation
val istanceId = FirebaseInstanceId.getInstance().getId()
Replacement
Checking out the code of FirebaseInstanceId#getId()
I saw the suggestion that you should use FirebaseInstallations#getId
instead.
This method is deprecated
Use
FirebaseInstallations.getId()
instead.
val instanceId = FirebaseInstallation.getInstance().getId()
FirebaseInstanceId class is deprecated, to get token use FirebaseMessagingClass. The token can be generated using the following code:
FirebaseMessaging.getInstance().getToken()
.addOnCompleteListener(new OnCompleteListener<String>() {
@Override
public void onComplete(@NonNull Task<String> task) {
if (!task.isSuccessful()) {
Log.w(TAG, "Fetching FCM registration token failed", task.getException());
return;
}
// Get new FCM registration token
String token = task.getResult();
// Log and toast
String msg = getString(R.string.msg_token_fmt, token);
Log.d(TAG, msg);
Toast.makeText(MainActivity.this, msg, Toast.LENGTH_SHORT).show();
}
});
Regarding the Firebase InstanceId, this is what the official document says:
public Task getInstanceId () -> This method is deprecated. For an instance identifier, use FirebaseInstallations.getId() instead. For an FCM registration token, use FirebaseMessaging.getToken() instead.