1

I'm trying to get a unique device info from Android OS.

Before Android 6.0 it's possible to get a WiFi MAC as a unique device info but from 6.0 it's impossible to get it anymore and I couldn't find any information.

I found some ideas as below but it's not perfect.

  1. Secure.ANDROID_ID : After factory reset, ID will be changed and I couldn't find a way to prove whether it's really unique or not.
  2. Build.SERIAL : Some manufacturer such as HTC, Samsung is providing totally different way to get it.

Is there anybody has some ideas? Please help me.

Thank you.

Daenam Kim
  • 127
  • 6
  • 1
    Do you just need a unique id or something that is actually tied to the device (i.e., if someone were to factory reset their device and give it to someone else would you still want the same ID?)? – ianhanniballake Nov 23 '15 at 23:12
  • Consider identifying the app installation instead of the device. Save a `UUID` in `SharedPreferences` and use that as your ID. – Kevin Krumwiede Nov 23 '15 at 23:27
  • Possible duplicate of [Android unique id](http://stackoverflow.com/questions/3115918/android-unique-id) – mbmc Nov 23 '15 at 23:29

3 Answers3

2

Settings.Secure.ANDROID_ID is pretty much the way to go. A nice feature of it is that it provides a different ID for each user on the device, which adds a nice level of flexibility for free.

As for the factory reset thing, you have to think about 1) What percentage of your users will actually do this, and 2) If someone is willing to nuke their device and delete all content, apps, and associations, do they really want your app to be able to identify their device anymore anyway? Or if someone factory resets and then sells or transfers the device to a new user, would you still want that device to be identified with the previous user?

If you get to that point and Settings.Secure.ANDROID_ID is still not good enough, a better solution is likely for you to have a login process and store data remotely.

NoChinDeluxe
  • 3,446
  • 1
  • 16
  • 29
  • another "nice" thing about Settings.Secure.ANDROID_ID is that users can actually modify it. Although root is probably required. – marcinj Nov 24 '15 at 00:09
  • @marcinj - But again, if this is a big enough problem for your scenario that you just can't take that risk, then having users login to a remote server with secure accounts is likely the better option. I would never tie any personal/secure info to a device ID. In my apps I use it purely for telemetry. – NoChinDeluxe Nov 24 '15 at 15:13
1

IMEI is good:

try {
  TelephonyManager tm = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);
  if (tm.getPhoneType() == TelephonyManager.PHONE_TYPE_NONE)
    return "";
  return tm.getDeviceId();
} catch (Throwable e) {
  return null;
}
marcinj
  • 48,511
  • 9
  • 79
  • 100
0

You should find this url very useful: https://plus.google.com/+AndroidDevelopers/posts/DMshVTyzqcL

kleinsenberg
  • 1,323
  • 11
  • 15