Android Imei与DeviceId
如果设备是单卡手机则 mTelephonyManager.getImei(0) 与 mTelephonyManager.getDeviceId(); 两者返回的值一样的,都是设备有IMEI码,
但如果手机是双卡的则mTelephonyManager.getDeviceId(); 与 mTelephonyManager.getImei(1) 返回的值是相同的,
判断当前设备是否为双卡
TelephonyManager mTelephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); mIsMultiSim = mTelephonyManager.getPhoneCount() > 1 ;
完整代码: String deviceId; if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { deviceId = Settings.Secure.getString( context.getContentResolver(), Settings.Secure.ANDROID_ID); android.util.Log.i("androidodm","00 deviceId ="+deviceId); }else { final TelephonyManager mTelephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); final boolean mIsMultiSim = mTelephonyManager.getPhoneCount() > 1; android.util.Log.i("androidodm","mIsMultiSim ="+mIsMultiSim); final String meid = mTelephonyManager.getImei(0); android.util.Log.i("androidodm","0-Imei ="+meid); if(mIsMultiSim){ final String meid1 = mTelephonyManager.getImei(1); android.util.Log.i("androidodm","1-Imei ="+meid1); } // if (!TextUtils.isEmpty(meid)) { if (mTelephonyManager.getDeviceId() != null) { deviceId = mTelephonyManager.getDeviceId(); android.util.Log.i("androidodm","11 deviceId ="+deviceId); } } return deviceId;
Imei与DeviceId是相同的,但 android_id与前两者的值是不相同的
版权声明:如无特殊标注,文章均为本站原创,转载时请以链接形式注明文章出处。
评论
sancaiodm
回复aaa