Android gets the phone's CPU and determines whether it's a single or multicore _android

Source: Internet
Author: User
Copy Code code as follows:

/**
* 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;
}
}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.