标签:初始 user rac ati static ring 硬件 tin pen
由于android版本升级升的问题,导致好多手机无法获取唯一标识,一下是获取手机标识的方法
1 private String getuuid(){ 2 String uuid = ""; 3 String serial = null; 4 5 String m_szDevIDShort = "35" + 6 Build.BOARD.length() % 10 + Build.BRAND.length() % 10 + 7 8 Build.CPU_ABI.length() % 10 + Build.DEVICE.length() % 10 + 9 10 Build.DISPLAY.length() % 10 + Build.HOST.length() % 10 + 11 12 Build.ID.length() % 10 + Build.MANUFACTURER.length() % 10 + 13 14 Build.MODEL.length() % 10 + Build.PRODUCT.length() % 10 + 15 16 Build.TAGS.length() % 10 + Build.TYPE.length() % 10 + 17 18 Build.USER.length() % 10; //13 位 19 20 try { 21 serial = android.os.Build.class.getField("SERIAL").get(null).toString(); 22 //API>=9 使用serial号 23 uuid = new UUID(m_szDevIDShort.hashCode(), serial.hashCode()).toString(); 24 } catch (Exception exception) { 25 //serial需要一个初始化 26 serial = "serial"; // 随便一个初始化 27 //使用硬件信息拼凑出来的15位号码 28 uuid = new UUID(m_szDevIDShort.hashCode(), serial.hashCode()).toString(); 29 } 30 return md5(uuid).substring(8, 24).toString().toUpperCase(); 31 } 32 33 private static String md5(String string) { 34 if (TextUtils.isEmpty(string)) { 35 return ""; 36 } 37 MessageDigest md5 = null; 38 try { 39 md5 = MessageDigest.getInstance("MD5"); 40 byte[] bytes = md5.digest(string.getBytes()); 41 StringBuilder result = new StringBuilder(); 42 for (byte b : bytes) { 43 String temp = Integer.toHexString(b & 0xff); 44 if (temp.length() == 1) { 45 temp = "0" + temp; 46 } 47 result.append(temp); 48 } 49 return result.toString(); 50 } catch (NoSuchAlgorithmException e) { 51 e.printStackTrace(); 52 } 53 return ""; 54 }
通过获取手机相应的硬件信息,用md5加密后返回唯一标识。
标签:初始 user rac ati static ring 硬件 tin pen
原文地址:https://www.cnblogs.com/jiaxuekai/p/13287672.html