IMEI是International Mobile Equipment Identity的缩写,国际移动设备识别码。手机序列号,保存在手机的EEPROM里。
public String getIMEI(Context context) {
String imei = "null";
try {
TelephonyManager tm = (TelephonyManager) context.getSystemService(TELEPHONY_SERVICE);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
imei = tm.getDeviceId();
} else {
Method method = tm.getClass().getMethod("getImei");
imei = (String) method.invoke(tm);
}
} catch (Exception e) {
e.printStackTrace();
}
return imei;
}
IMSI是International Mobile Subscriber Identity的缩写,国际移动用户识别码。保存在SIM卡里。
public String getIMSI(Context context) {
TelephonyManager tm =
(TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
if (tm == null) return "";
return tm.getSubscriberId();
}
通过以上函数获取这两个号时,需要app申请android.permission.READ_PHONE_STATE权限。