cesarsicas
cesarsicas

Reputation: 467

Firebase doesn't update token after call getToken(true)

So, i am using the combination of:

//retrieve actual token
FirebaseInstanceId.getInstance().instanceId.addOnSuccessListener

//force delete instance and then get a new token
FirebaseInstanceId.getInstance().deleteInstanceId();

But both are deprecated, and now i'm trying to use the combination of

//retrieve actual token
FirebaseMessaging.getInstance().token.addOnCompleteListener 

//force get new token
FirebaseInstallations.getInstance().getToken(true).addOnSuccessListener

To achieve the same behavior, but its not working.

When i call FirebaseMessaging.getInstance() it gives me a different token of FirebaseInstallations.getInstance().getToken

For example:

On app start, FirebaseMessaging.getInstance().token give me the token:

abcabcabcabcabcabcabcabc...

Then, when i call FirebaseInstallations.getInstance().getToken(true), i receive the token

123123123123123123123123123...

I close the app, open again, and FirebaseMessaging.getInstance().token gives me the same old token:

abcabcabcabcabcabcabcabc...

Upvotes: 0

Views: 1134

Answers (1)

Sinner of the System
Sinner of the System

Reputation: 2966

FirebaseInstanceId is not the same as messaging token. You should use Firebase.messaging.token to get the current token and Firebase.messaging.deleteToken() to force get a new one.

Or without ktx extensions: FirebaseMessaging.getInstance().getToken() and FirebaseMessaging.getInstance().deleteToken()

Upvotes: 1

Related Questions