如何从"/proc/cpuinfo"获取Android设备的特定信息;文件? [英] How to get specific information of an Android device from "/proc/cpuinfo" file?
问题描述
如何解析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());
这篇关于如何从"/proc/cpuinfo"获取Android设备的特定信息;文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!