2

My understanding of tokens is that they assign a token ID to the device and not the app.

I was wondering if its possible to generate a new FCM token ID. I want generation of a new token ID in the cases were two people use the same mobile device. Do not want an instance were someone reads someone elses notification despite using two different accounts.

Currently using an emulator for testing, and two of my users have the same token. The tokens were produced days ago, and FCM still generates the same token on the same emulator. Is there a function that produces a new unique FCM token?

  • The token is for App, and you can retrieve through FirebaseInstanceId.getInstrance().getToken(). You will receive new token if you unistall app or deleted data of app. For change token you have to save on your file or shareddata or db, and deleted when someone make logout – LorenzoBerti Oct 26 '16 at 14:54
  • So how does that work? When I run the app, and FirebaseInstanceId.getInstrance().getToken() is called, the log function prints out the same token that is saved in my Database. How does fire base know whether or not a token was deleted in the database? Not sure how deleting the token in the database will cause Firebase to give me a new token. –  Oct 26 '16 at 21:39
  • Firebase will give you new token when is refreshed or you unistall app or delete data for the app. If you close app, and reopen the token is the same, unless Firebase decides that the token is to be updated. if you have a app where more user can do a login (like me that I'm trying to solve, in this method) I believe, after research, that best method is save "current" token in sharedPref and in your db or file and if you want user_id and when you make new login, delete old token associated to old user in your db and refresh last id and last token. – LorenzoBerti Oct 27 '16 at 06:23
  • See this link to [get a unique id](https://stackoverflow.com/a/60395582/8532604) on each try – Hassan Alizadeh Feb 25 '20 at 21:58

0 Answers0