Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TelephonyManager returns null for IMEI number: what can cause this?

I'm working on an Android app and am getting null back for the IMEI number when using TelophonyManager. This is happening on several Huawei phones. (All of them are Ascend Y530s).

The phones all have sim cards and otherwise seem to be operating normally. I was under the impression that only a broken phone would return null IMEI. Clearly this is not the case..

Questions. What exactly is this IMEI number - i.e where is it stored on the device? And what does it mean when a seemingly fine phone returns its value as null?

EDIT

I should mention that the IMEI number is not always null. About half the time it seems to be valid (though this is very difficult to measure since we have 5 phones returning null IMEI numbers \ sometimes )

like image 785
Zach Smith Avatar asked Feb 02 '16 15:02

Zach Smith


1 Answers

After your comment, to get unique device id for the survey app, i would suggest you to use Settings.Secure.ANDROID_ID as your unique id.

String   myAndroidDeviceId = Secure.getString(getApplicationContext().getContentResolver(), Secure.ANDROID_ID);

Or you can use both as

public String getUniqueID(){    
    String myAndroidDeviceId = "";
    TelephonyManager mTelephony = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    if (mTelephony.getDeviceId() != null){
        myAndroidDeviceId = mTelephony.getDeviceId(); 
    }else{
         myAndroidDeviceId = Secure.getString(getApplicationContext().getContentResolver(), Secure.ANDROID_ID); 
    }
    return myAndroidDeviceId;
}
like image 164
Let'sRefactor Avatar answered Oct 25 '22 00:10

Let'sRefactor