Android Get Processor Model

You don’t need to implement separated methods to work with differ processors types, just simply replace the model_name key to cpu_model when it needed while getting /proc/cpuinfo file:

    public static Map<String, String> getCPUInfo () throws IOException {

        BufferedReader br = new BufferedReader (new FileReader ("/proc/cpuinfo"));

        String str;

        Map<String, String> output = new HashMap<> ();

        while ((str = br.readLine ()) != null) {

            String[] data = str.split (":");

            if (data.length > 1) {

                String key = data[0].trim ().replace (" ", "_");
                if (key.equals ("model_name")) key = "cpu_model";

                output.put (key, data[1].trim ());

            }

        }

        br.close ();

        return output;

    }

Leave a Comment