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

我们两清 提交于 2019-11-30 03:26:37

问题


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 )


回答1:


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;
}


来源:https://stackoverflow.com/questions/35157444/telephonymanager-returns-null-for-imei-number-what-can-cause-this

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!