当前位置: 移动技术网 > 移动技术>移动开发>Android > android获取手机cpu并判断是单核还是多核

android获取手机cpu并判断是单核还是多核

2019年07月24日  | 移动技术网移动技术  | 我要评论
复制代码 代码如下:

/**
* gets the number of cores available in this device, across all processors.
* requires: ability to peruse the filesystem at "/sys/devices/system/cpu"
* @return the number of cores, or 1 if failed to get result
*/
private int getnumcores() {
//private class to display only cpu devices in the directory listing
class cpufilter implements filefilter {
@override
public boolean accept(file pathname) {
//check if filename is "cpu", followed by a single digit number
if(pattern.matches("cpu[0-9]", pathname.getname())) {
return true;
}
return false;
}
}

try {
//get directory containing cpu info
file dir = new file("/sys/devices/system/cpu/");
//filter to only list the devices we care about
file[] files = dir.listfiles(new cpufilter());
//return the number of cores (virtual cpu devices)
return files.length;
} catch(exception e) {
//default to return 1 core
return 1;
}
}

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网