android 获取CPU个数
android获取CPU的数量,已封装成方法可直接使用
public static int getNumCpuCores() { // Private Class to display only CPU devices in the directory listing class CpuFilter implements java.io.FileFilter { @Override public boolean accept(java.io.File pathname) { // Check if filename is "cpu", followed by a single digit number if (java.util.regex.Pattern.matches("cpu[0-9]+", pathname.getName())) { return true; } return false; } } try { // Get directory containing CPU info java.io.File dir = new java.io.File("/sys/devices/system/cpu/");// 根据自己手机实际目录修改 // Filter to only list the devices we care about java.io.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 Log.e(TAG, "Failed to count number of cores, defaulting to 1", e); return 1; } }
版权声明:如无特殊标注,文章均为本站原创,转载时请以链接形式注明文章出处。
评论