如何从“/proc/cpuinfo"获取Android设备的特定信息文件? [英] How to get specific information of an Android device from "/proc/cpuinfo" file?

查看:36
本文介绍了如何从“/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,例如,

      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());
      

    • 这篇关于如何从“/proc/cpuinfo"获取Android设备的特定信息文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆