7

I have a web app that persists a user ID and firebase notification token per user. The user and token is created on Android device and send to the server, so server knows where to send notifications (because of the token).

The issue here is, that one user can be logged in on multiple devices. If the user is on two devices, then I should send notification to both devices. The web app knows 2 tokens for the one user ID. That is OK.

But what if I uninstall and install the application on the same device. I get a new token for the user, so I save it to web app, but then I have 3 tokens for one user ID. That is not correct as I should have only 2 tokens (the one token is OLD).

I know that I can save the DEVICE ID too (UUID), so I know that on that one device the token has been changed, so I can delete the old one for the device. BUT that for Android SDK 23 and higher I need to ask for a special permission to read the UUID. But I do not want to bother the users to ask for the permission to access UUID.

So I have the problem here. I want to keep only VALID tokens for the one user ID on my web app (if the user has 2 phones, then I should keep only 2 tokens for the user), but I do not know how without users accepting the permission.

Please help me here, I really could not find the standard solution and answer for this :( I guess there is some standard solution.

Thanks!

Petr Kott
  • 111
  • 7

1 Answers1

0

How do you try to get the unique id that it asks permission?

Try this one please, it seems not to ask any runtime permissions

Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
Andranik
  • 2,729
  • 1
  • 29
  • 45
  • 1
    Thanks. This I can use, but some manufactures of Android return the same ANDROID_ID for all their phones.... But I guess I have to live with that – Petr Kott Mar 19 '18 at 12:19
  • 1
    Do you have concrete examples of such manufactures? I used this in several apps, but didn't hear about problem, or may be I don't know if there is a problem... – Andranik Mar 20 '18 at 12:38
  • about the uniqueness of `ANDROID_ID`: https://stackoverflow.com/q/4799394/4671300 – talz Jul 12 '18 at 11:17