k0tt
k0tt

Reputation: 78

Best way to link a FCM token to a device?

I'm making a server that sends messages using FCM to clients depending on what happens (temperature and/or humidity change, a door is opened, etc.).

But if the token can change, how can I keep track of the device to send messages to the correct one (w/o using a login system)?

I was thinking to link the token to the sim iccid in a database, is this correct?

Upvotes: 1

Views: 2750

Answers (2)

AL.
AL.

Reputation: 37768

Update 05/18/2017:

Starting Android O, ANDROID_ID will now be different per app per user in the device.


Original Answer:

If you're looking for a long lasting (possibly permanent) ID that you can use, I guess you can make use of ANDROID_ID:

String ANDROID_ID

A 64-bit number (as a hex string) that is randomly generated when the user first sets up the device and should remain constant for the lifetime of the user's device. The value may change if a factory reset is performed on the device.

Note: When a device has multiple users (available on certain devices running Android 4.2 or higher), each user appears as a completely separate device, so the ANDROID_ID value is unique to each user.

Constant Value: "android_id"

However, there are still some factors that you should consider depending on your use-case. I recommend going through the Best Practices for Unique Identifiers documentation.

FCM wise, it is usually associated with a user, hence it is commonly paired with the user details.

Upvotes: 2

s3nzoM
s3nzoM

Reputation: 2187

Use device's advertising id. It won't change unless the user manually changes it. Please check the thread How to get Advertising ID in android

Upvotes: 1

Related Questions