某些山寨机可能拿不到IMEI
如果非要IMEI可以模拟一个
private String getUniqueId() {
TelephonyManager tm = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
String uniqueId=tm.getDeviceId();
if(isEmpty(uniqueId)){
uniqueId=android.os.Build.SERIAL;
}
if(isEmpty(uniqueId)){
uniqueId=Settings.System.getString(getContentResolver(), Settings.System.ANDROID_ID);
}
if(isEmpty(uniqueId)){
uniqueId=getUUID(context);
}
return uniqueId;
}
private String getUUID(Context context){
String uuid=(String)SPUtils.get(context, "DeviceId", "");
if(isEmpty(uuid)){
uuid = UUID.randomUUID().toString();
SPUtils.put(context, "DeviceId", uuid);
}
return uuid;
}