7

I'm facing now a big issue. As found in Android official reference: http://developer.android.com/reference/android/provider/Settings.Secure.html#ANDROID_ID


public static final String ANDROID_ID

*Added in API level 3

A 64-bit number (as a hex string) that is randomly generated on the device's first boot and should remain constant for the lifetime of the device. (The value may change if a factory reset is performed on the device.) Constant Value: "android_id"*


But with over 500 tablet sold (A10 AllWinner) ANDROID_ID is not really generated randomly and I see (from my web service log) that several devices have the same number!

Why?

How can I solve this issue? How can I generate a unique ID? Assume that the serial code is always the same for all devices (Same serial number on several android devices. Adb is useless. How can I change the serial number?) and MAC address could not be always available.

Community
  • 1
  • 1
Seraphim's
  • 12,559
  • 20
  • 88
  • 129
  • What are you using this number for that requires uniqueness? – CodesInChaos Feb 15 '13 at 11:17
  • My application uses C# web services to get updates, send data... So, in web services, I want to identify every single tablet I sold. It's a big problem if two or more tablet have the same identification number! – Seraphim's Feb 15 '13 at 11:19
  • 2
    Also worth noting that Android ID is reset if your user does a reset to factory defaults. – Elemental Feb 15 '13 at 11:24
  • possible duplicate of [Is Secure.ANDROID\_ID unique for each device?](http://stackoverflow.com/questions/4799394/is-secure-android-id-unique-for-each-device) – kellyfj Mar 25 '14 at 17:32

1 Answers1

11

In general this is a serious problem with Android - it seems the Android ID is the best option BUT as you note several significant vendors have made a mess of the implementation.

Confronted by a similar requirement I have used a hash of these values:

  • Phone number/SIM card number (if available or just use zeros)
  • Android ID
  • Mac Address (if available or just use zeros)

In my limited experience (several hundred devices in use) this combination has been good enough to achieve the uniqueness you need.

Update 2017 from Android 6 the Mac address returns a constant value for security reasons - however in almost all newer implementations of android the android ID seems to be reliably unique so unless you are targeting older versions you would have no motive to use this technique.

Elemental
  • 7,365
  • 2
  • 28
  • 33
  • something like that? http://www.java2s.com/Code/Android/Core-Class/getUniqueIDfromandroidproviderSettingsSecureANDROIDID.htm – Seraphim's Feb 15 '13 at 11:32
  • yep something like that - although a common well-understood hash algorithm would be better to combine the results. – Elemental Feb 15 '13 at 13:09
  • any specific suggestion? :) – Seraphim's Feb 15 '13 at 14:23
  • 1
    google found this http://www.javamex.com/tutorials/collections/hash_function_guidelines.shtml for me which seems well thought out and a good introduction. – Elemental Feb 16 '13 at 10:28
  • 2
    From Android 6 you can't use getMacAddress() for security reasons. It will just return a a constant value of 02:00:00:00:00:00. For more info see this question: http://stackoverflow.com/questions/33159224/getting-mac-address-in-android-6-0 – lejonl Jan 18 '17 at 22:55