In which cases the IMEI of a mobile device is not available?


I have an application that needs to download data, for that the IMEI of the device has been previously registered in the base, the problem has worked well, now that I use a device with API 27 the IMEI returns it to me null.

public  String getIMEINumber() {
    String IMEINumber = "";
    if (ActivityCompat.checkSelfPermission(this, 
    android.Manifest.permission.READ_PHONE_STATE) == 
    PackageManager.PERMISSION_GRANTED) {
        TelephonyManager telephonyMgr = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            IMEINumber = telephonyMgr.getImei();                
        } else {
            IMEINumber = telephonyMgr.getDeviceId();           
    return IMEINumber;

I have read and I see that the documentation says that it returns null if the IMEI is not available, I wonder in what cases it is not available? (if I have added the permissions in the MANIFEST)

asked by Igmer Rodriguez 31.08.2018 в 01:04

2 answers


There are several situations where you could not get the value of the IMEI, the first is that permission is necessary

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

but for versions greater than 6.0 you must manually require the permission.

  if (checkSelfPermission(Manifest.permission.READ_PHONE_STATE)
                    != PackageManager.PERMISSION_GRANTED) {
                requestPermissions(new String[]{Manifest.permission.READ_PHONE_STATE},

If you are using an emulator this may not get an IMEI value.

You try to get an IMEI on a device that is not phone like a tablet, you would not get IMEI.

Sometimes TelephonyManger.getDeviceId() gets a null value, so if you want an identifier for all your devices, I can recommend this method in which, if the value obtained is null (using getImei() or getDeviceId() ) also use Settings.Secure.ANDROID_ID that returns an ID as a single 64-bit hexadecimal string:

public String getUniqueID(){    
    String myAndroidDeviceId = "";
    TelephonyManager mTelephony = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    if (mTelephony.getDeviceId() != null){
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            myAndroidDeviceId = mTelephony.getImei(); 
        } else {
            myAndroidDeviceId = mTelephony.getDeviceId(); 
         myAndroidDeviceId = Secure.getString(getApplicationContext().getContentResolver(), Secure.ANDROID_ID); 
    return myAndroidDeviceId;
answered by 31.08.2018 в 01:55

The cause may be that the device does not have IMEI, since only devices that support telephone line (for normal calls and SMS) have this identifier (IMEI). For example some tablets do not support telephone line (IMEI).

If you do not have the device with you to verify that it supports telephone line, you can search it on the web for the model and brand.

If you confirm that this is the problem and your application requires this Identifier (IMEI), you would have to exclude these devices from the ones supported by your application.

answered by 01.09.2018 в 02:31