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

后端 未结 1 363
陌清茗
陌清茗 2021-01-04 20:58

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

相关标签:
1条回答
  • 2021-01-04 21:20

    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;
    }
    
    0 讨论(0)
提交回复
热议问题