您的位置:首页 > 移动开发 > Android开发

android手机唯一识别码

2015-09-23 17:39 806 查看
// http://blog.csdn.net/billpig/article/details/6728573 public UUID DeviceUuidBuild(Context context) {
synchronized (this)
{
if( uuid == null)
{
final SharedPreferences prefs = context.getSharedPreferences( PREFS_FILE, 0);
final String id = prefs.getString(PREFS_DEVICE_ID, null );

if (id != null)
{
uuid = UUID.fromString(id);
}
else
{
final String androidId = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
try {
if (!"9774d56d682e549c".equals(androidId)) //在主流厂商生产的设备上,有一个很经常的bug,就是每个设备都会产生相同的ANDROID_ID:9774d56d682e549c
{
uuid = UUID.nameUUIDFromBytes(androidId.getBytes("utf8"));
}
else
{
final String deviceId = ((TelephonyManager) context.getSystemService( Context.TELEPHONY_SERVICE )).getDeviceId();
uuid = deviceId != null ? UUID.nameUUIDFromBytes(deviceId.getBytes("utf8")) : UUID.randomUUID();
}
}
catch (UnsupportedEncodingException e)
{
throw new RuntimeException(e);
}
prefs.edit().putString(PREFS_DEVICE_ID, uuid.toString() ).commit();
}
}
}

return uuid;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: