Android获取处理器模型

时间:2015-08-03 08:57:08

标签: android cpu processor info

我想让处理器模型与DU B​​ooster类似。 CPU模型包含ARM处理器版本和修订版。例如:ARMv7 Processor rev 3(v7l)

我试过这个 System.getProperty("os.arch")仅返回架构

String[] args = {"/system/bin/cat", "/proc/cpuinfo"}; 

获取CPU信息。我能够在某些设备中获得正确的信息,但不是全部。

我在华硕Fonepad 7中尝试了这个,它没有返回处理器的属性(但返回处理器(小p)

它返回

processor   : 0
vendor_id   : GenuineIntel
cpu family  : 6
model       : 53
model name  : Intel(R) Atom(TM) CPU Z2520  @ 1.20GHz
stepping    : 1
microcode   : 0x10e
cpu MHz     : 800.000
cache size  : 512 KB
physical id : 0
siblings    : 4

我希望得到像" ARMv7 Processor rev 3(v7l)" 这样的结果。在此先感谢..

2 个答案:

答案 0 :(得分:11)

您不需要实现分离的方法来处理不同的处理器类型,只需在获取model_name文件时只需将cpu_model密钥替换为/proc/cpuinfo:< / p>

    public static Map<String, String> getCPUInfo () throws IOException {

        BufferedReader br = new BufferedReader (new FileReader ("/proc/cpuinfo"));

        String str;

        Map<String, String> output = new HashMap<> ();

        while ((str = br.readLine ()) != null) {

            String[] data = str.split (":");

            if (data.length > 1) {

                String key = data[0].trim ().replace (" ", "_");
                if (key.equals ("model_name")) key = "cpu_model";

                String value = data[1].trim ();

                if (key.equals ("cpu_model"))
                  value = value.replaceAll ("\\s+", " ");

                output.put (key, value);

            }

        }

        br.close ();

        return output;

    }

答案 1 :(得分:1)

这是一种简单的方法,您可以使用模式进行,但需要大量的TaE(试验和错误)

String unparsed_CPU_INFO;

onCreate{

        // cpu info
                    String result = null;
                    CMDExecute cmdexe = new CMDExecute();
                    try {
                        String[] args = {"/system/bin/cat", "/proc/cpuinfo"};
                        result = cmdexe.run(args, "/system/bin/");
                        Log.i("result", "result=" + result);
                    } catch (IOException ex) {
                        ex.printStackTrace();
                    }


                    unparsed_CPU_INFO = result;

System.out.println("Your cpu model is: " ++ getCPUName());
}

    public synchronized String getCPUName() {
                if (cpuName == null) {
                    String CPUName = "";

                    String[] lines = unparsed_CPU_INFO.split("\n");

                    for (int i = 0; i < lines.length; i++) {

                        String temp = lines[i];

                        if (lines[i].contains("Processor\t:")) {

                            CPUName = lines[i].replace("Processor\t: ", "");
                            break;
                        }
                    }
                    cpuName = CPUName;
                    return CPUName;
                } else {
                    return cpuName;
                }
            }