I\'m developing an application and I don\'t know how can I get CPU usage and temperature, example in a textview.
I try with TYPE_AMBIENT_TEMPERATURE to get temp
As OWADVL answered, you can ready the temperature also as a system file, like this:
int temperature = readSystemFileAsInt("sys/class/thermal/thermal_zone0/temp");
note that the readSystemFileAsInt is not a system call. I found the implementation here
private static int readSystemFileAsInt(final String pSystemFile) throws Exception {
InputStream in = null;
try {
final Process process = new ProcessBuilder(new String[] { "/system/bin/cat", pSystemFile }).start();
in = process.getInputStream();
final String content = readFully(in);
return Integer.parseInt(content);
} catch (final Exception e) {
throw new Exception(e);
}
}
private static final String readFully(final InputStream pInputStream) throws IOException {
final StringBuilder sb = new StringBuilder();
final Scanner sc = new Scanner(pInputStream);
while(sc.hasNextLine()) {
sb.append(sc.nextLine());
}
return sb.toString();
}
About the CPU usage (load) you can look at this question and already working solution by Souch at his gitHub here