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
Here's my solution, in Kotlin, based on this one:
/**
* return the number of cores of the device.
* based on : http://stackoverflow.com/a/10377934/878126
*/
private var coresCount: Int = 0
get() {
if (field > 0)
return field
class CpuFilter : FileFilter {
override fun accept(pathname: File): Boolean {
return Pattern.matches("cpu[0-9]+", pathname.name)
}
}
try {
val dir = File("/sys/devices/system/cpu/")
val files = dir.listFiles(CpuFilter())
if (files != null) {
field = files.size
return field
}
} catch (ignored: Exception) {
}
field = max(1, Runtime.getRuntime().availableProcessors())
return field
}