,

Resolved! FirebaseInstanceIdService is deprecated

So after updating the version of firebase-messaging in the build.gradle file from v17.0.0 to v17.1.0, strange things started happening… there was a line of horror in service I used to use for messaging in my application. After some research, I landed on this page. Let’s quickly go to updates which we need to do to…

By.

•

min read

So after updating the version of firebase-messaging in the build.gradle file from v17.0.0 to v17.1.0, strange things started happening…

there was a line of horror in service I used to use for messaging in my application. After some research, I landed on this page.

Let’s quickly go to updates which we need to do to get it working like before.

Now there is no need of FirebaseInstanceIdService to get token, so just delete it and also remove it from AndroidManifest.xml as well.

Method onTokenRefresh() is depriciated. Now we need to override onNewToken() method to get new token.

public class MyFirebaseMessagingService extends FirebaseMessagingService {

    @Override
    public void onNewToken(String token) {
        super.onNewToken(token);
        Log.e("Refreshed token:",token);
    }

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        super.onMessageReceived(remoteMessage);
    }
}

 

Method getToken() which we used in Activity is also depriciated now. Use getInstanceId() as follow

FirebaseInstanceId.getInstance().getInstanceId().addOnSuccessListener( MyActivity.this,  new OnSuccessListener<InstanceIdResult>() {
     @Override
     public void onSuccess(InstanceIdResult instanceIdResult) {
           String updatedToken = instanceIdResult.getToken();
           Log.e("Updated Token",updatedToken);

     }
 });

 

I hope this will help in time of crises 😛

Leave a Reply

Your email address will not be published. Required fields are marked *