Skip to content

Instantly share code, notes, and snippets.

@sajjadintel
Created December 4, 2017 17:52
Show Gist options
  • Save sajjadintel/7d76379e82d51efd0a24e5829c3ce572 to your computer and use it in GitHub Desktop.
Save sajjadintel/7d76379e82d51efd0a24e5829c3ce572 to your computer and use it in GitHub Desktop.
Get the CPU temperature from an android device by using the sys/class/thermal/temp command.
public float getCpuTemp() {
Process process;
try {
process = Runtime.getRuntime().exec("cat sys/class/thermal/thermal_zone0/temp");
process.waitFor();
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = reader.readLine();
float temp = Float.parseFloat(line) / 1000.0f;
return temp;
} catch (Exception e) {
e.printStackTrace();
return 0.0f;
}
}
@bakialmaci
Copy link

Thank you 👍

@zeeshan-mehdi
Copy link

line = null
in my case means it is reader.readLine() is returning null

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment