get Max Cpu frequency - Android Hardware

Android examples for Hardware:CPU Frequency

Description

get Max Cpu frequency

Demo Code


//package com.java2s;

import java.io.IOException;
import java.io.InputStream;

public class Main {
    public static String getMaxCpuFreq(int cpuNo) {
        String result = "";
        String path = "/sys/devices/system/cpu/cpu%d/cpufreq/cpuinfo_max_freq";
        ProcessBuilder cmd;/*from  ww  w.j a  v  a2 s . co m*/
        try {
            String[] args = { "/system/bin/cat", String.format(path, cpuNo) };
            cmd = new ProcessBuilder(args);
            Process process = cmd.start();
            InputStream in = process.getInputStream();
            byte[] re = new byte[24];
            while (in.read(re) != -1) {
                result += new String(re);
            }
            in.close();
        } catch (IOException ex) {
            ex.printStackTrace();
            result = "N/A";
        }
        return result.trim();
    }
}

Related Tutorials