3

I'm using firebase to push notifications in my android app.

I have sql database that stores user id , his token and login status (logged in - not logged in) to check before sending notification.

Everything working perfectly till I thought of this scenario, What if the user uninstall the app? the login will always be true and he will still receive notification. Cause I did some research and I found out that I can not detect when the user will uninstall the app so I could update his login status.

Any idea what should I do? Or do you have any better idea than storing the login status? cause for now the user can not logout from application unless he has internet connection so I could be able to update his login status via API. Which doesn't make sense. But i couldn't find any other idea.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
rav
  • 211
  • 5
  • 14

1 Answers1

3

If the user uninstalls the app, the device token provided by Firebase Cloud Messages will become invalid over time. You can detect this situation using the downstream message error response codes. In particular, pay attention to devices that are "not registered", with whatever client library or protocol you're using. Note that this is not necessarily a guarantee that the user uninstalled the app, but is a generalized way of dealing with any FCM device token that becomes invalid over time.

See also these answers:

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • Does "over time" slightly imply that it's possible for the app user getting two (or more) notifications on the same device? Given the app server does not very well manage its "inactive" tokens? – stdout Feb 09 '22 at 18:15