獲得我們手機的cpu序列號
阿新 • • 發佈:2019-02-07
/** * 獲取CPU序列號 * * @return CPU序列號(16位) * 讀取失敗為"0000000000000000" */ public static String getCPUSerial() { String str = "", strCPU = "", cpuAddress = "0000000000000000"; try { //讀取CPU資訊 Process pp = Runtime.getRuntime().exec("cat /proc/cpuinfo"); InputStreamReader ir = new InputStreamReader(pp.getInputStream()); LineNumberReader input = new LineNumberReader(ir); //查詢CPU序列號 for (int i = 1; i < 100; i++) { str = input.readLine(); if (str != null) { //查詢到序列號所在行 if (str.indexOf("Serial") > -1) { //提取序列號 strCPU = str.substring(str.indexOf(":") + 1, str.length()); //去空格 cpuAddress = strCPU.trim(); break; } }else{ //檔案結尾 break; } } } catch (IOException ex) { //賦予預設值 ex.printStackTrace(); } return cpuAddress; }