android获得手机uuid
2016-07-05 17:43
447 查看
private final String PREFS_FILE = "device_id.xml"; private final String PREFS_DEVICE_ID = "device_id"; private UUID uuid;
public String DeviceUuidFactory(Context context) { if( uuid == null) { final SharedPreferences prefs = context.getSharedPreferences( PREFS_FILE, 0); final String id = prefs.getString(PREFS_DEVICE_ID, null ); if (id != null) { // Use the ids previously computed and stored in the prefs file uuid = UUID.fromString(id); } else { final String androidId = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID); // Use the Android ID unless it's broken, in which case fallback on deviceId, // unless it's not available, then fallback on a random number which we store // to a prefs file try { if (!"9774d56d682e549c".equals(androidId)) { 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); } // Write the value out to the prefs file prefs.edit().putString(PREFS_DEVICE_ID, uuid.toString() ).commit(); } } return uuid.toString(); }
相关文章推荐
- 使用PowerShell .Net获取电脑中的UUID
- Shell脚本实现随机数多种方法介绍(date、random、uuid)
- Mysql中存储UUID去除横线的方法
- PHP中生成UUID自定义函数分享
- Javascript生成全局唯一标识符(GUID,UUID)的方法
- 用JS生成UUID的方法实例
- python uuid模块使用实例
- 基于时间UUID的妙用
- 使用PowerShell .Net获取电脑中的UUID
- UUID
- 网游服务器中的GUID(唯一标识码)实现-基于snowflake算法
- php 通用唯一识别码 UUID 扩展:uuidpp
- 查看 UUID
- 在spring data jpa使用UUID
- mysql 获取全局唯一值
- oc获取设备uuid
- 编写一个简单的COM组件
- 查询app包的uuid
- oracle数据库生成UUID的一个方法
- UUID.randomUUID()