獲取手機唯一標識


由於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加密后返回唯一標識。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM