Currently, only a few devices have a temperature sensor (for example, Samsung S4).
You should always check if the sensor is available, i.e. {
temperatureSensor = sensormanager.getDefaultSensor(Sensor.TYPE_AMBIENT_TEMPERATURE) if (temperatureSensor != null) { }
What you can do on HTC is to find another thermistor in the system and read the sysfs path where its value is displayed, for example, a thermistor in the battery or pressure sensor, if there is one in this phone.
The disadvantage of this approach is that these are the initial thermistor values - sometimes you need to know how to convert them to degrees Celsius, and worse, they are not compensated (because the temperature is from the API) - for example, if the phone does some calculations and the processor heats up the phone, this value can easily be 10 degrees higher than the ambient temperature and therefore not very useful ...
tpcz
source share