How to retrieve an Unique ID to identify Android devices ?

  • identify an Android user to store games scores on a server
  • track apps installation
  • generate DRM for copy protection.
  • IMEI for International Mobile Equipment Identity : the Unique Number to identify GSM, WCDMA mobile phones as well as some satellite phones
  • MEID for Mobile Equipment IDentifier : the globally unique number identifying a physical piece of CDMA mobile station equipment, the MEID was created to replace ESNs (Electronic Serial Number)
  • ESN for Electronic Serial Number : the unique number to identify CDMA mobile phones
  • IMSI (International Mobile Subscriber Identity) : the unique identification associated with all GSM and UMTS network mobile phone users
import android.telephony.TelephonyManager;
import android.content.Context;
// ...TelephonyManager telephonyManager;telephonyManager = (TelephonyManager) getSystemService(Context.
* getDeviceId() returns the unique device ID.
* For example,the IMEI for GSM and the MEID or ESN for CDMA phones.
String deviceId = telephonyManager.getDeviceId();
* getSubscriberId() returns the unique subscriber ID,
* For example, the IMSI for a GSM phone.
String subscriberId = telephonyManager.getSubscriberId();
String androidId = Settings.Secure.getString(getContentResolver(),
private static String uniqueID = null;
private static final String PREF_UNIQUE_ID = "PREF_UNIQUE_ID";
public synchronized static String id(Context context) {
if (uniqueID == null) {
SharedPreferences sharedPrefs = context.getSharedPreferences(
uniqueID = sharedPrefs.getString(PREF_UNIQUE_ID, null);
if (uniqueID == null) {
uniqueID = UUID.randomUUID().toString();
Editor editor = sharedPrefs.edit();
editor.putString(PREF_UNIQUE_ID, uniqueID);
return uniqueID;




Entrepreneur / Developer / Blogger / Author. In Bitcoin We Trust:

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Pair Programming: 1 year after

Advanced Threat Hunting for Persistence Using KQL (Kusto Query Language)

7 Benefits Of Icinga 2

Get Ready for Playoffs!

Mobile Apps Development

[DOWNLOAD] Getting Clojure: Build Your Functional Skills One Idea at a Time Full AudioBook

Data Pipelines at PasarPolis using Airflow and BigQuery

Skills To Become A Front End Developer In 2021

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Sylvain Saurel

Sylvain Saurel

Entrepreneur / Developer / Blogger / Author. In Bitcoin We Trust:

More from Medium

How to create a simple coroutine in Kotlin, Android

Geo-location tracking in Android with Kotlin

Drift Away From Android Handlers. Use Coroutines and Jobs Instead!

Accessing App Usage History In Android