Unique identifier for each user in Android

I want to allocate a unique identifier to each user as soon as he installs the application, so that whenever the application communicates with the server, I know who it communicates with. For this purpose, I thought that during the first installation, the application communicates with the server and receives a unique identifier. But I do not know where to store it forever, so that the next time the application starts, it knows that its identifier, and not contact the server.

Sorry if this is some obvious question as I'm a newbie.

+8
android
source share
4 answers

This question has been asked many times when the stack overflows.

In short: Android has always supported a unique identifier. However, prior to Android 2.2, the identifier was not always identical for some types of phones. Since 2.2 is pretty common, I would use this identifier.

The Android Developer blog has a good article on this.

And, as Joachim said, you can generally consider a different approach. Android's unique identifier is good and persistent with the factory reset, but not through a device update. Also keep in mind that many people have multiple devices (such as a phone and tablet). Instead, you can use a Google account, AccountManager can help you.

+6
source share

Use SharedPreferences to store a unique identifier.

Here is an example:

Android SharedPreferences

For more complex data, you can use SQlite.

0
source share

For a unique identifier, you can use the IMEI of the device on which the application will install. Refer to this link on how to get an IMEI number. Then save this IMEI number in your general preferences. To do this, refer to the Lillar Guillermo link. Before starting the application, you need to check this unique identifier. For the first time, save this preference. Therefore, the next time he checks this identifier, the application finds this in preference and, therefore, there is no need to connect the server. :)

0
source share

You can get IMEI devices. Starting with API 26, getDeviceId () is deprecated. If you need to get an IMEI device, use the following:

  String deviceId = ""; if (Build.VERSION.SDK_INT >= 26) { deviceId = getSystemService(TelephonyManager.class).getImei(); }else{ deviceId = getSystemService(TelephonyManager.class).getDeviceId(); } 
0
source share

All Articles