Unique Android Device ID for App Development and Tracking
Every Android device has a unique ID which differentiates it from other devices. Your Android Device ID is an alpha-numeric identification code stored inside an OS and can be accessed through official and hacking methods. 

Knowing your ID is a good reason for app developers and services to serve you better such as the number of people using their services, whether your device has particular service or app installed, statistics etc. 

Hacking is always possible, but all these devices help services get better insights by allowing a decent tracking, which is only possible with a unique Device ID.

If you want to know your device id there are apps which can help you through. Just search in google as 'android device id'. 

There are ways using which one can pull any Android device's unique id. 

Method 1

Settings.Secure#ANDROID_ID will return a unique 64-bit hex string Android ID.

import android.provider.Settings.Secure;

private String android_id = Secure.getString(getContext().getContentResolver(),


Method 2

Most of the smartphones will return value for TelephonyManager.getDeviceId()

For GSM use TelephonyManager.getDeviceId()
TelephonyManager.getSimSerialNumber() (with sim)

For CDMA use getSimSerialNumber()

ANDROID_ID & TelephonyManager.getDeviceId() both will work if user have added their Google account while setup.

In short, tm.getDeviceID() can be universally used anywhere.

final TelephonyManager tm = (TelephonyManager) getBaseContext().getSystemService(Context.TELEPHONY_SERVICE);

    final String tmDevice, tmSerial, androidId;
    tmDevice = "" + tm.getDeviceId();
    tmSerial = "" + tm.getSimSerialNumber();
    androidId = "" + android.provider.Settings.Secure.getString(getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);

    UUID deviceUuid = new UUID(androidId.hashCode(), ((long)tmDevice.hashCode() << 32) | tmSerial.hashCode());
    String deviceId = deviceUuid.toString();

code credits and source: by Joe on stackoverflow

Method 3 Using ANDROID_ID (Source - Android Develope Blog)

As per Android Developer Blog, ANDROID_ID is the most preferred device 

identifier. But again, there are incidents found for broken ANDROID_ID.

As per Google's recommendations, one can use a class (public DeviceUuidFactory) that can generate UUID for each device. To use this codes head to stackoverflow discussion - by emmby.

Method 4 Using 'Pseudo ID'

Using a pseudo id codes one can get unique device ID as hardware and software changes are likely to occur with every user across a globe. 

Considering higher guarantee of uniqueness, Pseudo code will give a perfect unique ability.

One can use below pseudo code.

if API => 9/10: (99.5% of devices)

return unique ID containing serial id (rooted devices may be different)


return unique ID of build information (may overlap data - API < 9)

Note: As most of the android devices are API 9 or above, one is likely to get guaranteed results.

Method 5 Using Google Play Services InstanceID

It is Google's own advertisingid client which defines the android user. It completely replaces existing user identification with advertising ID whenever Google play service is available. 

In case service is unavailable it is indicated by GooglePlayServicesNotAvailableException being thrown by getAdvertisingIdInfo().

Using the Class Settings.get() and Settings.set()

These classes use simple database based key value settings implementation. Using public class DeviceID you can pull any Android's unique device ID.

Head here for Ante's article for complete codes.

Your suggestions and comments are highly welcome. Please share here in comments.

Comment with Facebook

No more post found.