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 )

Let'sRefactor
  • 3,303
  • 4
  • 27
  • 43
Zach Smith
  • 8,458
  • 13
  • 59
  • 133
  • could you please try dialling *#06#, and confirm whether the phone got a valid [IMEI](https://en.wikipedia.org/wiki/International_Mobile_Station_Equipment_Identity) number? – Let'sRefactor Feb 02 '16 at 16:20
  • 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#? – Zach Smith Feb 02 '16 at 16:58
  • please contact the client request them to confirm it for you – Let'sRefactor Feb 02 '16 at 17:04
  • 1
    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 us – Zach Smith Feb 02 '16 at 17:34
  • Ok, got it, for your need i can give you an answer which helps you :) – Let'sRefactor Feb 02 '16 at 17:50
  • 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 faulty – Zach Smith Feb 02 '16 at 17:54
  • But yes. I've just confirmed that the code sometimes didn't work on those phones – Zach Smith Feb 02 '16 at 17:55
  • Sometimes TelephonyManger.getDeviceId() will return null, please see the answer i've posted, and check if it helps you – Let'sRefactor Feb 02 '16 at 17:59
  • I am Getting IMEI null on Android Q. is there any workaround for this? – Aman Verma Mar 15 '19 at 00:40
  • 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 imeis – Zach Smith Mar 15 '19 at 08:42

1 Answers1

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;
}
Let'sRefactor
  • 3,303
  • 4
  • 27
  • 43