Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
514 views
in Technique[技术] by (71.8m points)

linux kernel - How to get specific information of an Android device from "/proc/cpuinfo" file?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
  • 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<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;
    }
    

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...