获取安卓应用芯片CPU序列号(芯片ID)

前提是需要有root权限,才能执行adb命令。
主要是通过adb 命令:"cat /proc/cpuinfo"来读取cpu信息。
然后重数据流中截取Serial。
流程简单。
若是没有root权限,尝试使用以下adb命令获取root权限:
adb root
adb remount
adb  disable-verity
adb reboot
adb root
adb remount
adb shell


以下是android代码

public void getCPUinfo(String cmd){
String cmd = "cat /proc/cpuinfo";
    try {
        Process p = Runtime.getRuntime().exec(cmd);

        String data = null;
        BufferedReader ie = new BufferedReader(new InputStreamReader(p.getErrorStream()));
        BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
        String error = null;

        while ((error = ie.readLine()) != null
                && !error.equals("null")) {
            data += error + "\n";
        }

        String line = null;

        while ((line = in.readLine()) != null
                && !line.equals("null")) {
            data += line + "\n";
            ToastUtils.Log(line + "\n" , "CPUinfo");
            if (line.contains("Serial\t\t:")){
               String[] SerialStr =  line.split(":");
               if (SerialStr.length == 2){
                   String mSerial = SerialStr[1];
                   ToastUtils.show(MapManagerActivity.this, "CPU序列号:"+mSerial);
                   ToastUtils.Log("CPU序列号:"+mSerial.trim() , "CPUinfo");
               }
            }
        }
    }catch (IOException ioe){
        ioe.printStackTrace();
    }

}

你可能感兴趣的:(android)