问题
Is there any Java API for that? How can I read this information.
回答1:
To have frequency on Android, just read these special files in /sys directory:
#cat "/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq"
#cat "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq"
#cat "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq"
You will have current, min and max Frequency allowed.
回答2:
not MHz, but at least something. bogoMIPS value can be useful for you.
private String ReadCPUinfo()
{
ProcessBuilder cmd;
String result="";
try{
String[] args = {"/system/bin/cat", "/proc/cpuinfo"};
cmd = new ProcessBuilder(args);
Process process = cmd.start();
InputStream in = process.getInputStream();
byte[] re = new byte[1024];
while(in.read(re) != -1){
System.out.println(new String(re));
result = result + new String(re);
}
in.close();
} catch(IOException ex){
ex.printStackTrace();
}
return result;
}
回答3:
If you are interested in how long your system spent in what state, check out the file
/sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state
I'm not sure, whether root access is necessary for that.
来源:https://stackoverflow.com/questions/3021054/how-to-read-cpu-frequency-on-android-device