码迷,mamicode.com
首页 > 移动开发 > 详细

android手机唯一识别码

时间:2015-09-23 19:13:52      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:

   // 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;
    }
    

 

android手机唯一识别码

标签:

原文地址:http://www.cnblogs.com/yxc6123/p/4832933.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!