How do I change this code since FirebaseInstanceId and InstanceIdResult are deprecated? It also states 'cannot resolve method getToken()' from the code.
FirebaseInstanceId.getInstance().getId().addOnSuccessListener(new OnSuccessListener<InstanceIdResult>() {
@Override
public void onSuccess(InstanceIdResult instanceIdResult) {
String token = instanceIdResult.getToken();
if (!token.equals(session.getData(Session.KEY_FCM_ID))) {
UpdateToken(token, MainActivity.this);
}
}
});
CodePudding user response:
That's not how you should get the token. All those methods are deprecated. Nowadays, the solution is:
FirebaseMessaging.getInstance().getToken().addOnCompleteListener(new OnCompleteListener<String>() {
@Override
public void onComplete(@NonNull Task<String> task) {
if (task.isSuccessful()) {
String token = task.getResult();
//Do what you need to do with your token
Log.d(TAG, token);
}
}
});