Andriod 获取手机CPU型号设备信息 您所在的位置:网站首页 如何看手机系统版本和型号 Andriod 获取手机CPU型号设备信息

Andriod 获取手机CPU型号设备信息

2024-06-21 04:04| 来源: 网络整理| 查看: 265

环境 Mac mini 2014(Intel)Android Studio BumblebeeAndroid 手机 问题描述

获取手机 CPU 信息时,使用 Build.HARDWARE 只能获取到型号,没有 CPU 名称。

问题解决

注:写文章引用来源一直力求引用原创,但下面的引文没找到原创文献

面向搜索引擎编程,参考文献1 介绍了在 Windows 下的 shell 命令操作获取 CPU 信息。参考文献2 介绍了怎样解析出 CPU 名称,网上都是类似,但实际上获取的都不是 CPU 名称型号。

shell 命令获取 CPU 信息

在 Mac(Intel) 下 shell 命令获取 CPU 有两个途径,一是在 Mac 终端中,一是在 Android Studio 的 Terminal 里面,都是使用如下指令:

adb shell cat /proc/cpuinfo

所得结果如下:

Processor : AArch64 Processor rev 2 (aarch64) processor : 0 BogoMIPS : 3.84 Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 cpuid CPU implementer : 0x41 CPU architecture: 8 CPU variant : 0x0 CPU part : 0xd03 CPU revision : 4 processor : 1 BogoMIPS : 3.84 Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 cpuid CPU implementer : 0x41 CPU architecture: 8 CPU variant : 0x0 CPU part : 0xd03 CPU revision : 4 processor : 2 BogoMIPS : 3.84 Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 cpuid CPU implementer : 0x41 CPU architecture: 8 CPU variant : 0x0 CPU part : 0xd03 CPU revision : 4 processor : 3 BogoMIPS : 3.84 Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 cpuid CPU implementer : 0x41 CPU architecture: 8 CPU variant : 0x0 CPU part : 0xd03 CPU revision : 4 processor : 4 BogoMIPS : 3.84 Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 cpuid CPU implementer : 0x41 CPU architecture: 8 CPU variant : 0x0 CPU part : 0xd09 CPU revision : 2 processor : 5 BogoMIPS : 3.84 Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 cpuid CPU implementer : 0x41 CPU architecture: 8 CPU variant : 0x0 CPU part : 0xd09 CPU revision : 2 processor : 6 BogoMIPS : 3.84 Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 cpuid CPU implementer : 0x41 CPU architecture: 8 CPU variant : 0x0 CPU part : 0xd09 CPU revision : 2 processor : 7 BogoMIPS : 3.84 Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 cpuid CPU implementer : 0x41 CPU architecture: 8 CPU variant : 0x0 CPU part : 0xd09 CPU revision : 2 Hardware : Hisilicon Kirin970

由此可知,CPU 名称型号在最后一行。现有文章里面只是获取第一行肯定是不对的。

解析 CPU 名称型号

解析 CPU 名称型号,则应使用如下方法:

public static String getCpuName() { String str1 = "/proc/cpuinfo"; String str2 = ""; String cpuName = ""; try { FileReader fileReader = new FileReader(str1); BufferedReader bufferedReader = new BufferedReader(fileReader); while ((str2 = bufferedReader.readLine()) != null) { if (TextUtils.isEmpty(str2)) { continue; } String[] arrayOfString = str2.split(":\\s+", 2); if (TextUtils.equals(arrayOfString[0].trim(), "Hardware")) { cpuName = arrayOfString[1]; break; } } bufferedReader.close(); fileReader.close(); } catch (IOException e) { e.printStackTrace(); } return cpuName; } 参考文献

[1] android查看cpu信息 [2] Android获取系统cpu信息



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有