Many of us needs a unique id of the device or user for many reasons, it may be to get individual installations or to give the user info of multiple logins from different devices. For all these reasons one must have to use a device specific unique identifier. There are many options of this but we are here talking about the two mostly used.
- Device Id / IMEI Number
- Android Id
So here we will discuss the pros and cons of both the options. Its totally depends upon a persons need and usage to use one of them.
IMEI Number:
The imei number (International Mobile Equipment Identity) is a unique number thats mapped with every sim port of the device. You can see it on your devices battery and mainly used by the service providers. You can get it as
1 2 |
TelephonyManager manager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); manager.getDeviceId(); |
Pros:
- Its unchanged for an device, even factory reset can’t change the value.
- Its relaiable.
Cons:
- There are many android devices that doesn’t have a SIM port like tablets, android watches etc. For them there is no IMEI number available.
- As it persists factory resets and data wipes so you can’t be sure that the user of the device is not changed as someone can wipe his data off and pass his device to some other person.
Android Id:
Its a 64-bit number randomly generates when the device firstly boots. Its a secure number and it didn’t change during the lifetime of a device. But change when the factory reset is done. You can get it as
1 |
String android_id = Secure.getString(this.getContentResolver(), Secure.ANDROID_ID); |
Pros:
- As it changes with factory reset you can have an estimate/ probability that its a new user.
- It is available for all the android devices whether its tablet or android watch or android TV.
- Its unique of each device.
Cons:
- Its not reliable for the devices running below Froyo API.
So thats all about the two, the use of any one depends upon your needs and whichever suits you better.