Device ID:

  • device ID (device identification) is a distinctive number associated with a smartphone or similar handheld device.
  • Device IDs are separate from hardware serial numbers.

How do find my android device ID?

  1. Dial *#06#. The number should display on our screen.
  2. The IMEI / IMSI / MEID is displayed in the device’s phone status setting.
  3. The ID may be under or below the battery or on the back or bottom of the device.
  4. Use the number “0” instead of the letter “o”. Close.

Android ID:

[pastacode lang=”java” manual=”String%20androidID%20%3D%20Settings.Secure.getString(MainActivity.this.getContentResolver()%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20Settings.Secure.ANDROID_ID)%3B%0A” message=”java code” highlight=”” provider=”manual”/]

Device ID:

[pastacode lang=”java” manual=”String%20deviceID%20%3D%20((TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE))%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20.getDeviceId()” message=”java code” highlight=”” provider=”manual”/] [ad type=”banner”]
  • DeviceID: This is the serial of the device, which should persist even a factory reset.
  • AndroidID: This will be set at the first boot (either with a brand new device, or after a factory reset). As implicated, it does not survive a factory-reset
  • There’s a second “Android_ID” which is generated and used by the Google Services Framework (GSF), and thus often referenced as “GSF ID”. Behaves basically like the AndroidID mentioned before (e.g. doesn’t survive a factory-reset), and co-exists with it.
  • Furthermore, there’s the GAID (Google Advertising ID), which can be reset by the user via the Google Settings app.
  • During “normal operation” (i.e. as long as you not factory-reset your device or reset the GAID), all these IDs can be used to identify the device. When using multiple users (via user profiles) on a device, all except the DeviceID would even identify the user (profile).
[ad type=”banner”]

Tenets of Working with Android Identifiers

#: Avoid using hardware identifiers. Hardware identifiers such as SSAID (Android ID) and IMEI can be avoided in most use-cases without limiting required functionality.

#: Only use Advertising ID for user profiling or ads use-cases. When using an Advertising ID, always respect the Limit Ad Tracking flag, ensure the identifier cannot be connected to personally identifiable information (PII) and avoid bridging Advertising ID resets.

#: Use an Instance ID or a privately stored GUID whenever possible for all other use-cases except payment fraud prevention and telephony. For the vast majority of non-ads use-cases, an instance ID or GUID should be sufficient.

#: Use APIs that are appropriate to your use-case to minimize privacy risk. Use the DRM API API for high value content protection and the SafetyNet API for abuse prevention. The Safetynet API is the easiest way to determine whether a device is genuine without incurring privacy risk.

Settings.Secure#ANDROID_ID returns the Android ID as an unique for each user 64-bit hex string.

[pastacode lang=”java” manual=”import%20android.provider.Settings.Secure%3B%0A%0Aprivate%20String%20android_id%20%3D%20Secure.getString(getContext().getContentResolver()%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Secure.ANDROID_ID)%3B%20%0A” message=”java code” highlight=”” provider=”manual”/] [ad type=”banner”]
  • All devices tested returned a value for TelephonyManager.getDeviceId()
  • All GSM devices (all tested with a SIM) returned a value for TelephonyManager.getSimSerialNumber()
  • All CDMA devices returned null for getSimSerialNumber() (as expected)
  • All devices with a Google account added returned a value for ANDROID_ID
  • All CDMA devices returned the same value (or derivation of the same value) for both ANDROID_ID and TelephonyManager.getDeviceId() — as long as a Google account has been added during setup.

So if you want something unique to the device itself, TM.getDeviceId() should be sufficient. Obviously some users are more paranoid than others, so it might be useful to hash 1 or more of these identifiers, so that the string is still virtually unique to the device, but does not explicitly identify the user’s actual device. For example, using String.hashCode(), combined with a UUID:

Read the TelephonyManager properties, so add this to your manifest:

[pastacode lang=”java” manual=”%3Cuses-permission%20android%3Aname%3D%22android.permission.READ_PHONE_STATE%22%20%2F%3E%0A” message=”java code” highlight=”” provider=”manual”/] [pastacode lang=”java” manual=”final%20TelephonyManager%20tm%20%3D%20(TelephonyManager)%20getBaseContext().getSystemService(Context.TELEPHONY_SERVICE)%3B%20%0Afinal%20String%20tmDevice%2C%20tmSerial%2C%20androidId%3B%20%0AtmDevice%20%3D%20%22%22%20%2B%20tm.getDeviceId()%3B%20tmSerial%20%3D%20%22%22%20%2B%20tm.getSimSerialNumber()%3B%20%0AandroidId%20%3D%20%22%22%20%2B%20android.provider.Settings.Secure.getString(getContentResolver()%2C%20android.provider.Settings.Secure.ANDROID_ID)%3B%20%0AUUID%20deviceUuid%20%3D%20new%20UUID(androidId.hashCode()%2C%20((long)tmDevice.hashCode()%20%3C%3C%2032)%20%7C%20tmSerial.hashCode())%3B%20%0AString%20deviceId%20%3D%20deviceUuid.toString()%3B%20″ message=”java code” highlight=”” provider=”manual”/]

import libs

[pastacode lang=”java” manual=”import%20android.content.Context%3B%0Aimport%20android.telephony.TelephonyManager%3B%0Aimport%20android.view.View%3B%0A” message=”java code” highlight=”” provider=”manual”/]

Categorized in: