androidandroid-sensorstemperaturesamsung-galaxyandroid-hardware

How can I monitor temperature on a Samsung Galaxy S8 through code?


I'm trying to get access to the CPU temperature of Android devices, specifically the Samsung Galaxy S8 (for use with a GearVR) to be able to display it in the app interface. The TEMPERATURE and AMBIENT_TEMPERATURE sensors don't seem to be available, unless I've done something wrong in my code?

I tried getting the default AMBIENT_TEMPERATURE and TEMPERATURE sensors from the sensor manager, but both return null.

sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
ambTemperatureSensor = sensorManager.getDefaultSensor(Sensor.TYPE_AMBIENT_TEMPERATURE);
if(ambTemperatureSensor == null)
        message += "No ambient temperature sensor...\n";
temperatureSensor = sensorManager.getDefaultSensor(Sensor.TYPE_TEMPERATURE);
if(temperatureSensor == null)
        message += "No temperature sensor...\n";

I was fully expecting the AMBIENT_TEMPERATURE sensor to show up and give me access to the CPU temperature, but when that didn't work I thought maybe the deprecated TEMPERATURE sensor would be available instead. Do I need to do anything prior to calling getDefaultSensor?


Solution

  • The sensor AMBIENT_TEMPERATURE has only been present in the Galaxy S4, and Galaxy Note 3. This sensor is supposed to return the ambient temperature, not the CPU temperature. Your device does not have an ambient temperature sensor. You need to be looking for a way to read data from the internal sensors in the cpu, or battery of your device.

    Maybe this is what you are looking for:

    how get Current CPU Temperature programmatically in all Android Versions?