android - 从 android 设备获取 CPU 温度
问题描述
我正在尝试获取设备的温度。我使用了环境传感器(环境温度),但这不适用于大多数设备。我还使用了诸如“sys/class/thermal/thermal_zone0/temp”之类的命令,但没有运气。
请让我知道是否有人能够访问最新设备(例如(Samsung S10)、Vivi 1938)上的温度
解决方案
您可以使用以下代码获取设备的 CPU 温度:
public static float cpuTemperature()
{
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();
if(line!=null) {
float temp = Float.parseFloat(line);
return temp / 1000.0f;
}else{
return 51.0f;
}
} catch (Exception e) {
e.printStackTrace();
return 0.0f;
}
}
推荐阅读
- visual-studio - WebDeploy Publish:远程证书在几次后失效...... *尽管*反复接受它
- java - 无法理解 Graphics.getClipBounds() 和视口
- sql - 在 sql plus 中显示错误
- ios - 使用 AVAssetExportSession 后视频颜色错误
- javascript - nodejs 断言模块:assert.throws 只返回“未定义”
- c# - 如何在不为每个方法添加一行的情况下“记录”
- html - 使用 HTML 在 CSS 中添加背景图像
- python - 从 docker 内部,激活驻留在主机上的 Python 虚拟环境
- java - Jackson XmlMapper 映射嵌套元素的 XML 属性
- database - 我应该将上传的文件名存储在数据库中吗?