码迷,mamicode.com
首页 > 其他好文 > 详细

获取CPU信息

时间:2016-07-20 21:20:23      阅读:127      评论:0      收藏:0      [点我收藏+]

标签:

1 查看手机CPU信息

cmd——adb shell——cd /proc------cat cpuinfo

 

2 获取cpu的是arm指令集,armv7指令集、还是neon指令集

 

  1. /** 
  2.  *  
  3.  * [获取cpu类型和架构] 
  4.  *  
  5.  * @return  
  6.  * 三个参数类型的数组,第一个参数标识是不是ARM架构,第二个参数标识是V6还是V7架构,第三个参数标识是不是neon指令集 
  7.  */  
  8. public static Object[] getCpuArchitecture() {  
  9.     if ((Integer) mArmArchitecture[1] != -1) {  
  10.         return mArmArchitecture;  
  11.     }  
  12.     try {  
  13.         InputStream is = new FileInputStream("/proc/cpuinfo");  
  14.         InputStreamReader ir = new InputStreamReader(is);  
  15.         BufferedReader br = new BufferedReader(ir);  
  16.         try {  
  17.             String nameProcessor = "Processor";  
  18.             String nameFeatures = "Features";  
  19.             String nameModel = "model name";  
  20.             String nameCpuFamily = "cpu family";  
  21.             while (true) {  
  22.                 String line = br.readLine();  
  23.                 String[] pair = null;  
  24.                 if (line == null) {  
  25.                     break;  
  26.                 }  
  27.                 pair = line.split(":");  
  28.                 if (pair.length != 2)  
  29.                     continue;  
  30.                 String key = pair[0].trim();  
  31.                 String val = pair[1].trim();  
  32.                 if (key.compareTo(nameProcessor) == 0) {  
  33.                     String n = "";  
  34.                     for (int i = val.indexOf("ARMv") + 4; i < val.length(); i++) {  
  35.                         String temp = val.charAt(i) + "";  
  36.                         if (temp.matches("\\d")) {  
  37.                             n += temp;  
  38.                         } else {  
  39.                             break;  
  40.                         }  
  41.                     }  
  42.                     mArmArchitecture[0] = "ARM";  
  43.                     mArmArchitecture[1] = Integer.parseInt(n);  
  44.                     continue;  
  45.                 }  
  46.   
  47.                 if (key.compareToIgnoreCase(nameFeatures) == 0) {  
  48.                     if (val.contains("neon")) {  
  49.                         mArmArchitecture[2] = "neon";  
  50.                     }  
  51.                     continue;  
  52.                 }  
  53.   
  54.                 if (key.compareToIgnoreCase(nameModel) == 0) {  
  55.                     if (val.contains("Intel")) {  
  56.                         mArmArchitecture[0] = "INTEL";  
  57.                         mArmArchitecture[2] = "atom";  
  58.                     }  
  59.                     continue;  
  60.                 }  
  61.   
  62.                 if (key.compareToIgnoreCase(nameCpuFamily) == 0) {  
  63.                     mArmArchitecture[1] = Integer.parseInt(val);  
  64.                     continue;  
  65.                 }  
  66.             }  
  67.         } finally {  
  68.             br.close();  
  69.             ir.close();  
  70.             is.close();  
  71.         }  
  72.     } catch (Exception e) {  
  73.         e.printStackTrace();  
  74.     }  
  75.   
  76.     return mArmArchitecture;  
  77. }  

获取CPU信息

标签:

原文地址:http://www.cnblogs.com/lucktian/p/5689625.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!