How to get specific information of an Android device from “/proc/cpuinfo” file?

前端 未结 2 1390
予麋鹿
予麋鹿 2020-12-10 21:20

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 provide

2条回答
  •  青春惊慌失措
    2020-12-10 22:00

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

      you can get this information on with adb:

      adb shell cat /proc/cpuinfo
      

      adb shell cpuinfo

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

      public static Map getCpuInfoMap() {
          Map map = new HashMap();
          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;
      }
      

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

      try,

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

提交回复
热议问题