For some specific reasons I need to get the IMEI at some point in my Android app. Here is the code I use:
TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M){
// API available only >= 6.0
// Get first slot to avoid issue if we have multiple sim cards
String imei = tm.getDeviceId(0);
}
else
{
String imei = tm.getDeviceId();
}
It works fine in most cases. However some devices (like the Huawei Honor 7) offer dual-sim capability. In the settings, the user has the possibility to switch between the two SIM cards for 3G/4G support.
When I have two SIM cards and I do that switch, the IMEI I get is different.
As far as I know, the IMEI is related to a physical slot and should not change. This looks like bad implementation from the constructor.
Any idea for a workaround?