Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase instance id: deprecation of getId() in 21.0.0

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?

like image 635
Mahdi-Malv Avatar asked Oct 28 '20 13:10

Mahdi-Malv


People also ask

What is Firebase instance ID?

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.

How do I get Firebase instance ID in flutter?

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.

How do I find my device ID for Firebase?

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.

What is app instance ID?

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.


2 Answers

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.

like image 200
Midhun Murali Avatar answered Oct 18 '22 20:10

Midhun Murali


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()
like image 8
Mahdi-Malv Avatar answered Oct 18 '22 19:10

Mahdi-Malv