如何获得CPU温度? [英] How do I get the CPU temperature?

查看:446
本文介绍了如何获得CPU温度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道以某种方式可以获取CPU的温度,因为我下载了在无根设备中执行此操作的应用程序.怎么做?

I know it's somehow possible to get the CPU's temperature because I downloaded an app that does it in an unrooted device. How is it done?

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

edit: The application is called A1 CPU Tool. I spent several days searching for an answer.

edit2:这是我尝试的代码

edit2: Here's the code I tried

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温度详细信息,其中一个路径将返回所需的文件

Read the file from following paths (Since it is different for different devices) to get cpu temperature details from different devices, One of the path will return the needed file.

    "/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"    

要读取文件,我使用了:

To read the file, I used:

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

这是另一种方式:读取系统文件

这篇关于如何获得CPU温度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆