How can you detect a dual-core cpu on an Android device from code?

前端 未结 6 1822
小鲜肉
小鲜肉 2020-11-29 23:42

I\'ve run into a problem that appears to affect only dual-core Android devices running Android 2.3 (Gingerbread or greater. I\'d like to give a di

6条回答
  •  無奈伤痛
    2020-11-29 23:52

    I use a combination of both available solutions:

    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()
      )
    }
    

提交回复
热议问题