Android獲取手機cpu序列號的代碼
/**
- 獲取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++) {
} } catch (IOException ex) { //賦予默認值 ex.printStackTrace(); } return cpuAddress; }</pre>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; }
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!