With the recent release of FirebaseInstanceId and FirebaseCloudMessaging (21.0.0
) Firebase has deprecated iid
package and both getToken()
and getId()
methods are now deprecated.
According to the Firebase release note the method getToken()
is moved to FirebaseMessaging
Before:
FirebaseInstanceId.getInstance().getToken()
After:
FirebaseMessaging.getInstance().getToken()
Which gives use the fcmToken
, but to retrieve instance id, there's no method available in FirebaseMessaging nor FirebaseInstanceId.
So, Is instance_id
considered a useless id and should no longer be used? or is there a replacement for this?
Firebase Instance ID provides a unique identifier for each app instance and a mechanism to authenticate and authorize actions (example: sending FCM messages). Instance ID is stable except when: App deletes Instance ID. App is restored on a new device. User uninstalls/reinstall the app.
To retrieve the FirebaseInstanceId you need to implement the Firebase In-App messaging SDK and make sure your app connects to Firebase. Once the app is connected to Firebase it will add the FirebaseInstanceId to the Android log once the App is run.
In an iOS or Firebase app, device ID gets its value from the app-instance ID, which identifies a unique installation of the app. Device ID is one of the available reporting identity spaces.
Instance ID is unique across all app instances across the world, so your database can use it to uniquely identify and track app instances. Your server-side code can verify, via the Instance ID cloud service, that an Instance ID is genuine and is the same ID as the original app that registered with your server.
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.
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With