【Android获取CPU编号】生也有涯,知也无涯。这篇文章主要讲述Android获取CPU编号相关的知识,希望能为你提供帮助。
/**
* 获取CPU序列号
*
* @return CPU序列号(16位)
* 读取失败为"
0000000000000000"
*/
private static String getCPUSerial() {
if (Build.VERSION.SDK_INT >
= Build.VERSION_CODES.O) {
return Build.getSerial();
}
//读取CPU信息
InputStreamReader inputStreamReader = null;
BufferedReader bufferedReader = null;
String cpu = null;
try {
Process process = Runtime.getRuntime().exec("
cat /proc/cpuinfo"
);
inputStreamReader = new InputStreamReader(process.getInputStream());
bufferedReader = new BufferedReader(inputStreamReader);
while ((cpu = bufferedReader.readLine()) != null) {
if (cpu.contains("
Serial"
)) {
cpu = cpu.substring(cpu.indexOf("
:"
) + 1).trim();
break;
}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (bufferedReader != null) {
try {
bufferedReader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (inputStreamReader != null) {
try {
inputStreamReader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return cpu != null ? cpu.toUpperCase() : "
0000000000000000"
;
}
推荐阅读
- Android Studio安装虚拟机步骤
- 解读Android进程优先级ADJ算法
- app测试(兼容性测试)
- Android UI编程(ViewViewGroup类按钮TextViewEditText)
- android改机教程
- Android入门(创建编译运行打包安装)
- 发布app上架testflight
- Bmob后端云实现无后端开发APP
- Android跨平台投屏软件(无需root)--scrcpy