Question

Is it possible to implement a thermometer in Android? How?

I know that the BatteryManager can give you the battery temperature with BatteryManager.EXTRA_TEMPERATURE, but I'm not sure if this can be used to somewhat accurately measure the external temperature.

Was it helpful?

Solution

While StanislavK answer is technically correct, after reading the latest Android Compatibility Definition I've discovered that the thermometer sensor is deprecated, and if included, it must measure CPU temperature. From the official document:

Device implementations MAY but SHOULD NOT include a thermometer (i.e. temperature sensor.) If a device implementation does include a thermometer, it MUST measure the temperature of the device CPU. It MUST NOT measure any other temperature. (Note that this sensor type is deprecated in the Android 2.3 APIs.)

Thus, it appears that for the current version of Android it is not possible to implement an accurate thermometer.

OTHER TIPS

First, you must have a device with the thermometer sensor (a temperature sensor type). Then you might use it.

To check for the sensor, in code use SensorManager:

//get sensor manager first
SensorManager sensorMgr = (SensorManager)context.getSystemService(Context.SENSOR_SERVICE);

then use getSensorList and look for TYPE_TEMPERATURE .

Tips: Note, the temperature updates might be "slow" i.e. there might be one or two updates per minute. You might also consider to alow to calibrate your results (i.e. allow add/substract units to the built in sensor results based on a real measured temperature).

BTW: For an outside temeratures, you might use "current outside temperature" from the weather services like METAR (based on the current device location).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top