0

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!

do87
  • 197
  • 2
  • 8

2 Answers2

3

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);
AskNilesh
  • 67,701
  • 16
  • 123
  • 163
  • 1
    how if the apps already release then in next version we added fcm. In my case, for first installation is works fine, but when upgraded it was failed. onNewToken had never triggered. How do we call this method directly? – Nanda Z Sep 05 '20 at 02:00
0

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:

Hitesh Sarsava
  • 666
  • 4
  • 15