2

https://firebase.google.com/docs/cloud-messaging/android/client

  • Assume my app storing user's fcm token into my own server on user profile.
  • if the user has multiple device,then he will have multiple fcm id on his profile.
  • one of the mobile user uninstalls the app, then how to remove that fcm registered token id from user's profile which already stored.

1 Answers1

0

A simple solution is that when you are storing token of a user in your database then at the same time save the device's UUID as well which will identify that device. Now, if a user deletes the application and re-installs later then a new token will be sent to server from the same UUID. Detect that and update the old token.

Case 2 is that if user doesn't reinstall the app then would the token will remain save in DB?, to detect the application deletion a Receiver is implemented which detects event if user is upto delete the application (How can an app detect that it's going to be uninstalled?) . Inform your server about that event and disable that id. Why I'm not asking for deletion? The Receiver detects when user opens app deletion dialog. But what if user goes back and doesn't delete the app? in that case whenever user open's the application inform the server that app was not deleted. This thing could be handled by saving a boolean value in sharedPreferences.

Community
  • 1
  • 1
Usman Rana
  • 2,067
  • 1
  • 21
  • 32
  • In Case 1 : What if user uninstalls app from one device . Then tries logging in using another device ? – ANUJ GUPTA Jan 09 '18 at 15:40
  • @ANUJGUPTA . You can save the userId too. – Usman Rana Jan 09 '18 at 17:16
  • hi,now am facing same issue.But in Case1 UUID is unique only for app not device.how your handle this kind of scenario,Any hint bro? – Rgv Jul 02 '18 at 04:33
  • @Rgv while creating UUID you can exclude package name, and it will be for device then not for app only. – Usman Rana Jul 02 '18 at 06:09
  • thank you for repose,i read some articles they said impossible to get UUID in android and some once said use Settings.Secure.ANDROID_ID,but if factory reset then ANDROID_ID may change.so i confused,which one is the better way – Rgv Jul 02 '18 at 06:19
  • factory reset can be considered as rare case scenario, using ANDROID_ID is right approach as per my knowledge. – Usman Rana Jul 02 '18 at 09:32