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

set up device
set up my device
find my device
cannot find set up nearby device
find my device privacy
set up new device
find my device settings
set up my new device

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

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).

How to Use the Windows Device Manager for Troubleshooting, Let me explain to you this by device_info plugin. Step 1 Add Dependency dependencies: flutter: sdk: flutter device_info: ^0.4.0+1. Step 2 Import  DeviceObjectVersion: The device's object version number. DeviceOSType: The device operating system type. DeviceOSVersion: The device operating system version number. DeviceTrustType: The device trust type. The value could be one of the following: Workplace Joined, AzureAD Joined, Domain Joined.

In addition to the answer of Trevor Johns, you can use this as follows:

TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.getDeviceId();

And you should add the following permission into your Manifest.xml file:

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

In emulator, you'll probably get a like a "00000..." value. getDeviceId() returns NULL if device ID is not available.

How to open Windows Device Manager, This topics shows how to get the highest feature level supported by a device. Direct3D 11 devices support a fixed set of feature levels that are  How to Identify a Device in Windows. You can use the Device Manager to view hardware devices connected to your PC. To open it on Windows 10, right-click the Start button, and then select the “Device Manager” option. To open it on Windows 7, press Windows+R, type “devmgmt.msc” into the box, and then press Enter.

I use the following code to get the IMEI or use Secure.ANDROID_ID as an alternative, when the device doesn't have phone capabilities:

/**
 * Returns the unique identifier for the device
 *
 * @return unique identifier for the device
 */
public String getDeviceIMEI() {
    String deviceUniqueIdentifier = null;
    TelephonyManager tm = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
    if (null != tm) {
        deviceUniqueIdentifier = tm.getDeviceId();
    }
    if (null == deviceUniqueIdentifier || 0 == deviceUniqueIdentifier.length()) {
        deviceUniqueIdentifier = Settings.Secure.getString(this.getContentResolver(), Settings.Secure.ANDROID_ID);
    }
    return deviceUniqueIdentifier;
}

How to get device id in flutter, If you have a Mac device with you then the easiest method to obtain iOS device logs is by using Apple Configurator 2 and Xcode. Look for a device that has the “ADB” designation. In the following screenshot, we see it’s under “ACER Device.” Expand the group by clicking the little arrow on the left, then right-click on the device and select “Update Driver Software” from the context menu. If you don’t see anything with “ADB” in the name, you may have to

Or you can use the ANDROID_ID setting from Android.Provider.Settings.System (as described here strazerre.com).

This has the advantage that it doesn't require special permissions but can change if another application has write access and changes it (which is apparently unusual but not impossible).

Just for reference here is the code from the blog:

import android.provider.Settings;
import android.provider.Settings.System;   

String androidID = System.getString(this.getContentResolver(),Secure.ANDROID_ID);

Implementation note: if the ID is critical to the system architecture you need to be aware that in practice some of the very low end Android phones & tablets have been found reusing the same ANDROID_ID (9774d56d682e549c was the value showing up in our logs)

How To Get the Device Feature Level, Windows device log is records of events that occur in a Windows machine. These logs are critical in troubleshooting Windows devices. Gets a device from Active Directory. The Get-AzureADDevice cmdlet gets a device from Azure Active Directory (AD). This command gets the specified device. This command gets all available devices. If true, return all devices. If false, return the number of objects specified by the Top parameter. Specifies the oData v3.0 filter statement.

From: http://mytechead.wordpress.com/2011/08/28/how-to-get-imei-number-of-android-device/:

The following code helps in obtaining IMEI number of android devices :

TelephonyManager tm = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
String device_id = tm.getDeviceId();

Permissions required in Android Manifest:

android.permission.READ_PHONE_STATE

NOTE: In case of tablets or devices which can’t act as Mobile Phone IMEI will be null.

How to obtain iOS device logs using Mac and Windows, For a non-McAfee encrypted drive to be exempted, the device must be added to the FRP exemption list. For information about how to add the  Some parameters and settings may be exclusive to one environment or the other. Use the Get-MobileDevice cmdlet to get the list of devices in your organization that have active Exchange ActiveSync partnerships. For information about the parameter sets in the Syntax section below, see Exchange cmdlet syntax

How to get Windows device logs from a Windows machine, How to locate the device name on windows. 1. Open System Properties by one of the following ways: Windows Logo key + Break key; Right click My  How to Open Device Manager via Control Panel. Open Control Panel . In Windows 10 and Windows 8, assuming you're using a keyboard or mouse, the fastest way is through the Power User Menu What you do next depends on what Windows operating system you're using: In Windows 10 and Windows 8, select

How to identify Device IDs to add to the Removable Media , Follow these instructions to find your computer or mobile device's media access control address (MAC address). Follow the steps for the  d. Click Enable auto popup dialog when device has been plugged in. e. Click OK twice. f. Now, restart computer and check the issue. If the issue persists, I would suggest you to set the headphone or speaker that you are connecting as default and check if it helps. a) Right click on the volume icon in the system tray and then click "Recording

How to locate the device name of a machine, Open Windows Device Manager (Start → Run… → devmgmt.msc, OR right-click on My Computer → click Manage → select Device Manager from the System  When you add a device to Google Play, you can access your previous app, movie, music, book and other purchases on the new device. You can quickly add Android devices by signing in with the same Google account. If you have an Amazon Fire

Comments
  • To get IMEI for both SIM in dual SIM Phones use Java reflections. See here is demo
  • @PiedPiper: IMEI is not SIM-specific. You're thinking IMSI.
  • @Phillip Thanks mate. I have updated my answer :)
  • Everyone .. are there some changes in android 6? can we still access the IMEI by some means?
  • You need to request the Permission READ_PHONE_STATE at runtime, then you can still get the IMEI
  • What would be a better solution then which would enable them to migrate data in the future? Google email address? If so how can I pull that out from the system?
  • The most reliable way to do this is to just have them create an account the first time they launch your app. There are ways to get the user's email address (see the docs on AccountManager), but verifying that a malicious user hasn't forged this information requires a bit of knowledge about how the Google Data APIs work -- more than I can put in this small comment box. ;)
  • Actually, for that matter, you don't have any guarantee that the user hasn't forged their IMEI/MEID either. If security is of any concern, you really need to use either a username/password, or the getAuthToken() method in AccountManager (and again, you'd need to verify this token with the server that originally issued it).
  • Adi: The code for getting the device ID? There's nothing more than the one method + permission I mentioned above. That said, you should look into the Google+ Login API, that's the recommended approach for authenticating users these days: developer.android.com/google/play-services/auth.html
  • Is it running Android 6? And are you targeting SDK 23? Then you need to request READ_PHONE_STATE at runtime before querying the IMEI