How to get the number of cores of an android device

后端 未结 8 2120
挽巷
挽巷 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条回答
  •  囚心锁ツ
    2020-12-04 22:32

    Nice and simple solution in kotlin:

    fun getCPUCoreNum(): Int {
      val pattern = Pattern.compile("cpu[0-9]+")
      return Math.max(
        File("/sys/devices/system/cpu/")
          .walk()
          .maxDepth(1)
          .count { pattern.matcher(it.name).matches() },
        Runtime.getRuntime().availableProcessors()
      )
    }
    

提交回复
热议问题