14

I am developing an android app for my project, I need to find room temperature as part of it. I am using Droid 2 A955 model for testing.

My Questions are:

  1. What sensors need to be available in my Android phone to perform this temperature sensing task?

  2. Can Ambient Light Sensor (available in Droid 2) help in doing this task?

  3. Is there any Android api to find/sense room temperature programmatically in my android code?

Thanks in advance for your help.

Stephen Kennedy
  • 20,585
  • 22
  • 95
  • 108
talasila
  • 268
  • 1
  • 3
  • 9
  • #2 is either pointless or quite open ended. With some external items, almost anything could "help" for example you could point the camera at a thermometer, or aim a light that encodes the temperature at the light sensor. – Chris Stratton Aug 08 '11 at 17:53
  • Yes, I agree #2 is unrelated. But, I was doubting "Thermo" app in android market, how exactly this app is giving the room temp. Is it a fake app? "http://www.appbrain.com/app/thermo/com.antonio.thermo2.activity" – talasila Aug 08 '11 at 21:11
  • Why do you need a API? Use hardware sensor instead! EDIT I just found out that my mom's phone (Galaxy S4) is the only one supporting temperature sensor. – Confuse Sep 23 '14 at 11:17

9 Answers9

12

To answer all three of your questions in one fell swoop, no, I don't believe so. There can be a temperature sensor in android devices, but it senses the temperature of the battery, not the outside temperature. It would not provide an accurate gauge for that purpose.

I'm not sure how an ambient light sensor would help with temperature, it can be very bright out but it could be in an air conditioned room.

Lastly: there are lots of examples of temperature apps, but again, most are related to the battery.

Edit: Official documentation says:

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.)

Update:

API level 14 (i.e. Android 4.0) onwards, support for measuring ambient temperature has been added (via TYPE_AMBIENT_TEMPERATURE). [Android doc reference]

This, however, will work only on devices with ambient temperature sensor.

Gagan
  • 1,497
  • 1
  • 12
  • 27
Otra
  • 8,108
  • 3
  • 34
  • 49
  • Thanks for the reference, now I understand the usage of temp sensor in droid 2. – talasila Aug 08 '11 at 21:13
  • Does that mean that it is not possible to get environmental temperature around the phone in real time in any way? I am excluding GPS position of the forecast station in the town since I would need the temperature of the environment around the phone (room) – quant Feb 10 '19 at 09:45
11

It seems that there is a new sensor in the API.

This one is for the ambient temperature, but probably there are just a few devices with this implemented.

UPDATE: it seems that the Galaxy S4 is the first phone integrating ambient temperature sensor

OriolJ
  • 2,762
  • 1
  • 28
  • 22
2

You'll want to check out the Sensor reference docs. Offhand, I don't think there are accessible temperature sensors on-board most handhelds though.

Austin Hanson
  • 21,820
  • 6
  • 35
  • 41
2

Take a look at the Sensor class in the documentation.

You need to do something along the lines of this:

public class SensorActivity extends Activity, implements SensorEventListener {
 private final SensorManager mSensorManager;
 private final Sensor mTemp;

 public SensorActivity() {
     mSensorManager = (SensorManager)getSystemService(SENSOR_SERVICE);
     mtemp = mSensorManager.getDefaultSensor(Sensor.TYPE_TEMPERATURE);
 }

 protected void onResume() {
     super.onResume();
     mSensorManager.registerListener(this, mTemp, SensorManager.SENSOR_DELAY_NORMAL);
 }

 protected void onPause() {
     super.onPause();
     mSensorManager.unregisterListener(this);
 }

 public void onAccuracyChanged(Sensor sensor, int accuracy) {
 }

 public void onSensorChanged(SensorEvent event) {
 }
}

This should give you access to the temperature sensors in it's own activity.

Play with this and see what you can find. The documentation has great examples for other types of sensors, the temp sensor should be even simpler than most of the provided ones.

Hope this helps!

Nathaniel Ford
  • 20,545
  • 20
  • 91
  • 102
Codeman
  • 12,157
  • 10
  • 53
  • 91
  • 1
    Can you state for a fact that this provides an ambient temperature and not a CPU or battery temp? – Chris Stratton Aug 08 '11 at 17:51
  • 2
    This is in fact the battery/ CPU temperature. Android API 14 (Ice Cream Sandwich) now supports Sensor.TYPE_AMBIENT_TEMPERATURE. – Tom Dec 02 '11 at 11:54
1

You can use the iCelsius Wireless from Kickstarter. It has an API. It is impossible to measure accurately temperature using an internal sensor from a SmartPhone. It will always be few degree to high.

Kiwi44
  • 11
  • 1
0

i have same your question long time ago. And what my found is :

  • check this offical site for Environment sensor
  • this tuts for environment sensor : Ambient Temperature (room temp) Ambient Light ... Tutsplus. on my phone only Ambient Light work
  • now as i know only samsung galaxy S4 have Ambient Temperature. if you have S4 search Holo Ambient Temperature on gg playstore .
ntvfx
  • 21
  • 2
0

this sounds interesting:

http://developer.android.com/reference/android/hardware/Sensor.html#TYPE_AMBIENT_TEMPERATURE

from API >= 13

drdrej
  • 904
  • 8
  • 14
0

Try this one:

private float temperature = 0;

In onCreate put wìthis code:

    SensorManager mySensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
    Sensor AmbientTemperatureSensor
            = mySensorManager.getDefaultSensor(Sensor.TYPE_AMBIENT_TEMPERATURE);
    if (AmbientTemperatureSensor != null) {
        mySensorManager.registerListener(
                AmbientTemperatureSensorListener,
                AmbientTemperatureSensor,
                SensorManager.SENSOR_DELAY_NORMAL);
    }

And the method below:

private final SensorEventListener AmbientTemperatureSensorListener
            = new SensorEventListener() {

        @Override
        public void onAccuracyChanged(Sensor sensor, int accuracy) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onSensorChanged(SensorEvent event) {
            if (event.sensor.getType() == Sensor.TYPE_AMBIENT_TEMPERATURE) {
                temperature = event.values[0];
            }
        }

    };
savepopulation
  • 11,736
  • 4
  • 55
  • 80
Emulk
  • 1
  • 1
0

There is the age old method of letting the phone and a "good" thermometer stabilize at room temperature (a few hours) and read both.

Then put it outside in a nice wintry garage at about 35F let it stabilize. Then pray for linearity.

Empirical is always nice. I am very interested in measuring a constant temperature in an empty house, and watch for the temperature dropping (or rising!!)

Bradshaw at Buzzards Bay