Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop sending firebase notification when user uninstall the app

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.

like image 863
rav Avatar asked Nov 24 '25 13:11

rav


1 Answers

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:

  • Firebase Cloud Messaging - Managing Registration Tokens
  • Verify stored Firebase FCM tokens
like image 147
Doug Stevenson Avatar answered Nov 27 '25 03:11

Doug Stevenson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!