如何从"/proc/cpuinfo"获取Android设备的特定信息;文件?

问题描述:

如何解析Android平板电脑的/proc/cpuinfo虚拟文件以获取处理器核心和时钟速度的信息? 我不需要上述文件提供的所有信息;只是这两位. 有人可以帮忙吗?

How can I parse /proc/cpuinfo virtual file of my Android tablet to get information of the processor's core and clockspeed? I don’t need all information provided by the above file; just these two bits. Can someone please help?

  • 尚不清楚是要在应用程序中使用此信息,还是仅供自己使用.

    • It is not clear if you want this information inside your app, or just for your own use.

      您可以通过adb获取此信息:

      you can get this information on with adb:

      adb shell cat /proc/cpuinfo
      

      如果要在应用程序中使用此信息,请创建一个简单的函数以返回Map<String,String>,例如

      If you want to use this information in your app, create a simple function to return a Map<String,String>, for example,

      public static Map<String, String> getCpuInfoMap() {
          Map<String, String> map = new HashMap<String, String>();
          try {
              Scanner s = new Scanner(new File("/proc/cpuinfo"));
              while (s.hasNextLine()) {
                  String[] vals = s.nextLine().split(": ");
                  if (vals.length > 1) map.put(vals[0].trim(), vals[1].trim());
              }
          } catch (Exception e) {Log.e("getCpuInfoMap",Log.getStackTraceString(e));}
          return map;
      }
      

      请注意,这不会获得多个cpus信息,因此会被覆盖.无论如何,大多数值都是相似的.或修改以创建CpuInfoMap列表.

      Note, this will not get multiple cpus information, overwrites. Most of the values are similar anyways. or Modify to create List of CpuInfoMaps.

      尝试

      Log.d("getCpuInfoMap test", getCpuInfoMap().toString());