源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

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

  • 时间:2021-03-10 06:54 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:android获取手机cpu并判断是单核还是多核
[u]复制代码[/u] 代码如下:
/** * 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; } }
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部