16

I need to register user devices on server with an unique identifier that be a constant value and doesn't change in the future.

I can't find a good solution to get unique id from all devices (with/without simcard).

Secure.ANDROID_ID: Secure.ANDROID_ID is not unique and can be null or change on factory reset.

String m_androidId = Secure.getString(getContentResolver(), Secure.ANDROID_ID);

IMEI: IMEI is dependent on the Simcard slot of the device, so it is not possible to get the IMEI for the devices that do not use Simcard.

TelephonyManager tManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
String uuid = tManager.getDeviceId();

WLAN MAC Address: If device doesn’t have wifi hardware then it returns null MAC address. and user can change the device mac address.

WifiManager m_wm = (WifiManager)getSystemService(Context.WIFI_SERVICE); 
String m_wlanMacAdd = m_wm.getConnectionInfo().getMacAddress();

Bluetooth Address string:If device hasn’t bluetooth hardware then it returns null.

BluetoothAdapter m_BluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); 
String m_bluetoothAdd = m_BluetoothAdapter.getAddress();

Instance id: instance_id will change when user uninstalls and reinstalls app. and it's not a constant value.

Do you have any idea to get a unique id from all Android devices (with/without simcard, Bluetooth, ...) that really be unique, cannot be null and doesn't change after uninstall/reinstall app?

Milad Nouri
  • 1,587
  • 1
  • 21
  • 32
  • Notice that a tablet without both SIMcard and WiFi cannot exist or be remotely useful. Have you considered a combination of both? – STT LCU Sep 25 '15 at 10:28
  • @STTLCU no. but users can change devise MAC address. – Milad Nouri Sep 25 '15 at 10:33
  • @STTLCU I'm not sure what tablets you've got around you, but hardly anyone I know has a tablet _with_ a SIM card. – Matt Taylor Sep 25 '15 at 10:37
  • 2
    Android ID is officially designed for the purpose: http://android-developers.blogspot.hk/2011/03/identifying-app-installations.html , which means that there are probably no better substitutes. That it doesn't survive device wipe is deliberate. – headuck Sep 25 '15 at 10:43
  • 1
    Can I ask why the value has to stay constant even after a factory reset? If I'm selling my phone on, I sure as hell don't want anyone else to be able to access your server and get at my data. The `Secure.ANDROID_ID` seems to be ideal for this, what's your requirement that says otherwise? – Matt Taylor Sep 25 '15 at 10:43
  • You can combine all of them with an ID generated by you to make a Unique Combination. And build a pattern matching routine which will agree to identify the device if it meets some level of probability say 95% (in case one or more of them varies) – Techidiot Sep 25 '15 at 10:47
  • @MattTaylor probably I didn't explain myself, but what I meant that the probability to lack WiFi AND to lack a sim card in a single tablet is pretty much null. so an ID made by a combination of the two of them is guaranteed to be not null pretty much always. – STT LCU Sep 25 '15 at 11:07
  • @MiladNouri Why would you like to identify _device_ of each user. A user might buy a new device or lose its current device. IMO, you should identify each _user_ not their devices. Identifying users seems to be easy, for instance by their E-Mail accounts. – frogatto Sep 25 '15 at 11:45
  • @MiladNouri will you mind explaining the use case. That will help us understand the problem better. – Rahul Tiwari Sep 25 '15 at 12:11
  • Possible duplicate of [Is there a unique Android device ID?](http://stackoverflow.com/questions/2785485/is-there-a-unique-android-device-id) – matt. Jan 31 '16 at 18:23

3 Answers3

4

I found that Secure.ANDROID_ID is the best choice. This is a 64-bit quantity that is generated and stored when the device first boots. But it resets on device factory reset.

there are some reports that shows some devices has same Secure.ANDROID_ID on all instances.

we can add extra items (like sim serial, GCM instance id or ...) to the Secure.ANDROID_ID and generate new unique fingerprint.

Milad Nouri
  • 1,587
  • 1
  • 21
  • 32
3

Mutiple users can be setup on Android device and Secure.ANDROID_ID is different for every user on same Android device. So using Secure.ANDROID_ID means single devices will be registered as a different device for each user setup on the device.

0

Secure.ANDROID_ID is your only friend. However it has some problems (empty results) on older (<2.3) devices. All other ID's do not work on all type of devices.

Please also read Is there a unique Android device ID?

Community
  • 1
  • 1
userM1433372
  • 5,345
  • 35
  • 38