How do I get the CPU temperature?

后端 未结 5 1607
挽巷
挽巷 2020-12-10 04:39

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?

edit: The application is

5条回答
  •  执念已碎
    2020-12-10 04:56

    If a device doesn't expose CPU temperature via either temperature sensor (that is, asking for a sensor of type TEMPERATURE or AMBIENT_TEMPERATURE gives you nothing), you won't be able to read it in a standard manner. Of course, that says nothing about doing it in a non-standard way which might be suitable for your application if it's not going for wide distribution.

    You can read off device files in /sys/devices/platform if you know where to look. If you run adb shell and cd into that folder, you've got fairly good chances of find | grep temp giving you files representing temperature sensors.

    These files also aren't just going to be for the CPU only - as an example the battery temperature sensor for my Google Glass can be accessed by reading /sys/devices/platform/omap_i2c.1/i2c-1/1-0055/power_supply/bq27520-0/temp.

    Looking at that path it's clear why you shouldn't do this and expect it to work on all devices - the paths and also the formats of the files will vary from device to device. However in a pinch it's a quick and dirty way to get the job done.

提交回复
热议问题