TelephonyManager.getDeviceId(0) returns different results

笑着哭i 提交于 2019-12-02 04:34:50

As you said IMEI/Device Id is tagged to sim slot.

For dual SIM phones there are three IMEI values(one for each slot) and IMEI-SV.

Let’s say IMEI for slot 1 is: 123456789012345

IMEI for slot 2 is: 012500123456789

Depending on the scenarios, following is the returned value by telephonyManagerObj.getDeviceId():

  1. When you don’t have any SIM card, the method will return IMEI for slot1 i.e. 123456789012345
  2. When you have SIM card in slot 1, the method will return IMEI for slot1 i.e. 123456789012345
  3. When you have SIM card in both slots, the method will return IMEI for slot1 i.e. 123456789012345
  4. But when you have SIM card only in slot 2, the method will return IMEI for slot2 i.e. 012500123456789
  5. I found that on one device when I insert the SIM card incorrectly in slot 1 then the method returned IMEI-SV

One work around to maintain consistency is to store the IMEI in SharedPreference/Sqlite once you successfully managed to retrieve it.

So when you need IMEI value in your code, you can first check if its available in your local storage. If not available then retrieve the IMEI and store it for next time usage.

Be careful, getDeviceId() has been deprecated in Android O. Check this so for alternative

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