Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the device's IMEI/ESN programmatically in android?

Tags:

android

imei

To identify each devices uniquely I would like to use the IMEI (or ESN number for CDMA devices). How to access this programmatically?

like image 429
Tom Avatar asked Dec 29 '09 00:12

Tom


People also ask

How can I get IMEI number from ADB?

You can check and save the IMEI number of your device by dialing *#06# in your dialer app and taking a screenshot of it. Alternatively, you can use this ADB command on your PC. It will display the IMEI number in the Command Prompt, which you can copy and paste wherever you want for safekeeping.

Can Android apps read IMEI?

Android recognizes the importance of protecting the IMEI. In order for apps to access it, they must be granted the READ_PHONE_STATE permission (see figure above); only apps with that permission are allowed to access the IMEI.

How do I find my IMEI number on my kotlin Android?

Over time, Android provided functions such as getDeviceId() , getImei() (IMEI for GSM) or getMeid() (MEID for CDMA) to get IMEI information programmatically. Android deprecated the getDeviceId in Android 8.0 (API level 26) and above devices.


1 Answers

You want to call android.telephony.TelephonyManager.getDeviceId().

This will return whatever string uniquely identifies the device (IMEI on GSM, MEID for CDMA).

You'll need the following permission in your AndroidManifest.xml:

<uses-permission android:name="android.permission.READ_PHONE_STATE" />

in order to do this.

That being said, be careful about doing this. Not only will users wonder why your application is accessing their telephony stack, it might be difficult to migrate data over if the user gets a new device.

Update: As mentioned in the comments below, this is not a secure way to authenticate users, and raises privacy concerns. It is not recommended. Instead, look at the Google+ Login API if you want to implement a frictionless login system.

The Android Backup API is also available if you just want a lightweight way to persist a bundle of strings for when a user resets their phone (or buys a new device).

like image 145
Trevor Johns Avatar answered Oct 10 '22 01:10

Trevor Johns