Skip to content

Instantly share code, notes, and snippets.

@neshume
Forked from ValCanBuild/GetCpuTempAndroid.java
Created October 7, 2018 07:11
Show Gist options
  • Save neshume/9cfb41e1edeeb2e3931375195fff5e87 to your computer and use it in GitHub Desktop.
Save neshume/9cfb41e1edeeb2e3931375195fff5e87 to your computer and use it in GitHub Desktop.
A way to get the CPU temperature from an android device by using the sys/class/thermal/temp command
public float getCpuTemp() {
Process p;
try {
p = Runtime.getRuntime().exec("cat sys/class/thermal/thermal_zone0/temp");
p.waitFor();
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = reader.readLine();
float temp = Float.parseFloat(line) / 1000.0f;
return temp;
} catch (Exception e) {
e.printStackTrace();
return 0.0f;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment