linux下获取CPU 温度的节点:
cat /sys/class/thermal/thermal_zone0/temp
输出:53333,代表 53.333 度
android java代码
读取节点的方法
public static String readGpioPGForLong(String path) {
String str = "";
File file = new File(path);
try {
FileInputStream fileInputStream = new FileInputStream(file);
byte[] buffer = new byte[1024];
fileInputStream.read(buffer);
fileInputStream.close();
str = new String(buffer);
} catch (FileNotFoundException var5) {
var5.printStackTrace();
} catch (UnsupportedEncodingException var6) {
var6.printStackTrace();
} catch (IOException var7) {
var7.printStackTrace();
}
return str;
}
获取CPU 温度
//获取CPU 温度
public double getCPUTempe() {
String s = readGpioPGForLong("/sys/class/thermal/thermal_zone0/temp");
int temp = Integer.parseInt(s.substring(0, 5));
return temp / 1000;
}