do87
do87

Reputation: 207

Get new token firebase (FCM) for push notification

I am building an app has push notification.I want, when user login with difference account I will register new Firebase token to server. But after researching for some hours,it seems Firebase only generate new token when app was uninstalled.

So my question is,is possible to get new firebase token every time when user login with new account (in same device)? Thank in advance!

Upvotes: 1

Views: 7031

Answers (2)

AskNilesh
AskNilesh

Reputation: 69754

From Firebase Docs

The registration token may change when:

  • The app deletes Instance ID
  • The app is restored on a new device
  • The user uninstalls/reinstall the app
  • The user clears app data.

Retrieve the current registration token

When you need to retrieve the current token, call FirebaseInstanceId.getInstance().getToken(). This method returns null if the token has not yet been generated.

 String myRefreshedToken = FirebaseInstanceId.getInstance().getToken();
 Log.d( "myRefreshedToken" , myRefreshedToken);

Upvotes: 3

Hitesh Sarsava
Hitesh Sarsava

Reputation: 680

The registration token may change when:

1) The app deletes Instance ID

2) The app is restored on a new device

3) The user uninstalls/reinstall the app

4) The user clears app data.

see this official documents link when the new token can be generated for further more info:

Upvotes: 0

Related Questions