gpt4 book ai didi

android - 如何获取 CPU 温度?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:27:38 30 4
gpt4 key购买 nike

我知道以某种方式获取 CPU 的温度是可能的,因为我下载了一个应用程序,它可以在没有开启Root的设备上执行此操作。它是怎么做到的?

编辑:该应用程序称为 A1 CPU 工具。我花了几天时间寻找答案。

edit2:这是我试过的代码

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mSensorManager = (SensorManager)getSystemService(SENSOR_SERVICE);
Sensor TempSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_AMBIENT_TEMPERATURE);
mSensorManager.registerListener(temperatureSensor, TempSensor, SensorManager.SENSOR_DELAY_FASTEST);
}

private SensorEventListener temperatureSensor = new SensorEventListener(){

@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
// TODO Auto-generated method stub

}

@Override
public void onSensorChanged(SensorEvent event) {
// TODO Auto-generated method stub
float temp = event.values[0];
Log.i("sensor", "sensor temp = " + temp);
}
};

最佳答案

从以下路径读取文件(因为它因不同的设备而异)以从不同的设备获取 cpu 温度详细信息,其中一个路径将返回所需的文件。

    "/sys/devices/system/cpu/cpu0/cpufreq/cpu_temp"             
"/sys/devices/system/cpu/cpu0/cpufreq/FakeShmoo_cpu_temp"
"/sys/class/thermal/thermal_zone1/temp"
"/sys/class/i2c-adapter/i2c-4/4-004c/temperature"
"/sys/devices/platform/tegra-i2c.3/i2c-4/4-004c/temperature"
"/sys/devices/platform/omap/omap_temp_sensor.0/temperature"
"/sys/devices/platform/tegra_tmon/temp1_input"
"/sys/kernel/debug/tegra_thermal/temp_tj"
"/sys/devices/platform/s5p-tmu/temperature"
"/sys/class/thermal/thermal_zone0/temp"
"/sys/devices/virtual/thermal/thermal_zone0/temp"
"/sys/class/hwmon/hwmon0/device/temp1_input"
"/sys/devices/virtual/thermal/thermal_zone1/temp"
"/sys/devices/platform/s5p-tmu/curr_temp"

为了读取文件,我使用了:

RandomAccessFile reader = new RandomAccessFile("/sys/devices/system/cpu/cpu0/cpufreq/cpu_temp", "r");
String line = reader.readLine();

这是另一种方式:Read system files

关于android - 如何获取 CPU 温度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20771070/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com