Android 获取UUID两种方法
Android 获取UUID两种方法
·
第一种:SIM卡唯一标识 + DEVICE_ID(根据不同的手机设备返回IMEI,MEID或者ESN码)+androidId
这种方式获取的UUID是唯一不可变的,但是仅适用于手机中有SIM卡的情况。
private String getMyUUID(){
final TelephonyManager tm = (TelephonyManager) getBaseContext().getSystemService(Context.TELEPHONY_SERVICE);
final String tmDevice, tmSerial, tmPhone, androidId;
tmDevice = "" + tm.getDeviceId();
tmSerial = "" + tm.getSimSerialNumber();
androidId= "" + android.provider.Settings.Secure.getString(getContentResolver(),
android.provider.Settings.Secure.ANDROID_ID);
UUID deviceUuid = new UUID(androidId.hashCode(), ((long)tmDevice.hashCode() << 32) | tmSerial.hashCode());
String uniqueId = deviceUuid.toString();
Log.d("debug","uuid="+uniqueId);
return uniqueId;
}
第二种:这种方式获取的UUID是可变的,但是可以适用于各种形式。
private String getMyUUID(){
UUID uuid = UUID.randomUUID();
String uniqueId = uuid.toString();
Log.d("debug","----->UUID"+uuid);
return uniqueId;
}
更多推荐
已为社区贡献3条内容
所有评论(0)