0

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?

Jon
  • 25
  • 1
  • 9

2 Answers2

2

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?

Chrystian
  • 977
  • 3
  • 11
  • 24
0

Not every sensor exists on every device. Your device may not have a temperature sensor at all. That's one of the most likely ones not to exist, as the data was generally misinterpreted and not very useful.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
  • Thanks for the answer. I should've probably mentioned this in my question, but the Galaxy S8 has a built-in notification that tells users when it gets too hot; I take it it might have some sort of private temperature sensor that it only exposes to the OS then? – Jon May 21 '19 at 17:16
  • All devices seem to have at least a battery temperature sensor – Cornelius Roemer Dec 11 '19 at 19:49
  • @CorneliusRoemer Actually very few do. And battery temperature is useless- batteries produce waste heat, so its notgoing to be remotely accurate- it could be 10s of degree celsius high. – Gabe Sechan Dec 11 '19 at 19:50
  • This is an API for battery temperature - it works reliably on most if not all devices: https://stackoverflow.com/questions/3997289/get-temperature-of-battery-on-android Sure, it's not necessarily close to CPU temperature - but it's correlated. Better than nothing. – Cornelius Roemer Dec 11 '19 at 20:08