How to get the number of cores of an android device

后端 未结 8 2115
挽巷
挽巷 2020-12-04 21:44

I was looking to determine(or count) the number of cores in the embedded processor of android device.

I tried using /proc/cpuinfo, but it is not return

8条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-04 22:23

    Here you go (JAVA) :

        try {
            int ch, processorCount = 0;
            Process process = Runtime.getRuntime().exec("cat /proc/cpuinfo");
            StringBuilder sb = new StringBuilder();
            while ((ch = process.getInputStream().read()) != -1)
                sb.append((char) ch);
            Pattern p = Pattern.compile("processor");
            Matcher m = p.matcher(sb.toString());
            while (processorCount.find())
                processorCount++;
            System.out.println(processorCount);
        } catch (IOException e) {
            e.printStackTrace();
        }
    

提交回复
热议问题