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

1

10

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 )

Albertype answered 2/2, 2016 at 15:28 Comment(10)
could you please try dialling *#06#, and confirm whether the phone got a valid IMEI number?Commutable
These phones have been deployed remotely so I can't access them. As far as I have understood, our clients have never had a problem getting the IMEI number using *#06#?Albertype
please contact the client request them to confirm it for youCommutable
I will ask. They have provided me IMEI numbers at least 4 times and have never mentioned seeing null - these are the phones that are returning null for an IMEI number. I should mention that this doesn't happen all the time (I'd say about half the time). We have a survey application, each survey should send through an IMEI number, and without it they are anonymous which is not useful to usAlbertype
Ok, got it, for your need i can give you an answer which helps you :)Commutable
Do you have a reason for the imei number? We are using other identification methods at the moment... But I'm worried that the phones are faultyAlbertype
But yes. I've just confirmed that the code sometimes didn't work on those phonesAlbertype
Sometimes TelephonyManger.getDeviceId() will return null, please see the answer i've posted, and check if it helps youCommutable
I am Getting IMEI null on Android Q. is there any workaround for this?Chadwick
I created a uuid, and stored that. Then if you get an IMEI as null 9 times out of 10 you can then associate the imei that you get once with that uuid. This allows you to clean up null imeisAlbertype
W
9

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;
}
Wozniak answered 2/2, 2016 at 17:57 Comment(10)
Thank you. I will implement this tomorrow :)Albertype
Technically though, i'm interested to know what is the possible cause of this problem?Albertype
ok... gonna leave the question open in case someone knows. thanks for your helpAlbertype
is the for all phones?Albertype
Yes, for all phones @ZachSmithCommutable
Thanks we have implemented this fix and it achieves the desired resultAlbertype
I get a warning: using getString to get device identifiers is not recommendedLamrert
Getting IMEI null on Android Q? Did anyone find out this too?Chadwick
imei is restricted on Android 10 and up so that regular apps cannot get it: developer.android.com/about/versions/10/privacy/…Gambeson
is above solution will work for android 10 and above?Cessation

© 2022 - 2024 — McMap. All rights reserved.