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

You can try.

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

 public String getImei() {

    return telephonyManager.getDeviceId();
}
Add below permission into your Androidmanifest.xml file.
< uses-permission android:name="android.permission.READ_PHONE_STATE"/>