13

I am trying to get Unique ID[I.E unique id of a device] by using below code

TelephonyManager tManager;

tManager = (TelephonyManager).getSystemService(Context.TELEPHONY_SERVICE);

String deviceId = tManager.getDeviceId();

Where deviceId Gives me Unique ID for Android Device. I am not testing this on emulator because in emulator i am getting value 000000000000000

Any way i am testing it on real devices,and this works fine for mostly all devices , but in some device i am getting value null

I have tested this on

Samsung Galaxy S3

Samsung Galaxy Tab3

Samsung Galaxy Star

Google Nexus4

Google Nexus5

Google Nexus7

In all the devices listed above it gives me correct out put except one Device and that is Google Nexus7, in this i m getting value null

So, ultimately my goal is to get unique value for each particular device, In case if this code gives me null value than i can try some alternate way

i heard that Device MAC Address is a unique for all devices, But unfortunately it just works on wifi connection.

So is there any other way to get unique value of each particular device?

Thanks Any way

Aamirkhan
  • 5,746
  • 10
  • 47
  • 74
  • check this if it helps http://stackoverflow.com/questions/16869482/how-to-get-unique-device-hardware-id-in-android/16869491#16869491 – Raghunandan Feb 20 '14 at 14:05
  • 1
    what's the reason of down votes? Strange – Aamirkhan Feb 21 '14 at 04:03
  • You may use [this library](https://github.com/delight-im/Android-BaseLib) to generate a unique ID per device with [Identity.getDeviceId(context)](https://github.com/delight-im/Android-BaseLib/blob/master/Source/src/im/delight/android/baselib/Identity.java) that works in all cases. – caw Mar 08 '15 at 22:34

1 Answers1

14

You shouldn't really use the ANDROID_ID, you have no real guarantee that it will give you a unique identifier for the device and it is known that some older devices give the value null, or as in Moto's case, the same static value across multiple devices. This value also changes when the phone is reset to the factory default, and is super easy to change on a rooted device.

The correct way is to generate your own UUID via.

String uudid = UUID.randomUUID()

You then save this in your App, for example through a SharedPreference. You can then use Google's Android backup storage to retain this identifier even if the user uninstalls your App.

More information on Backup here: http://developer.android.com/guide/topics/data/backup.html

If you don't take my word for it, you should take Reto Meier's word for it, he is a developer advocate at the Google Android team. This video will explain what I just told you, check out around minute 15, he also specifically instructs developers not to use the ANDROID_ID.

http://www.youtube.com/watch?v=twmuBbC_oB8&list=WL86437554BC3E54B5

Ernir Erlingsson
  • 2,150
  • 1
  • 19
  • 17
  • @Aღmirkhan There is a wealth of good information in those Android I/O videos, I recommend taking a closer look at all of them. – Ernir Erlingsson Feb 21 '14 at 09:16
  • Would you like to give a tutorial link for backup identifier on google's android backup storage?! Thanks – Dr.jacky May 07 '15 at 04:11