Professional Documents
Culture Documents
IN ANDROID
ENVIRONMENTAL SENSORS :
Introduction:
The Android platform provides four sensors that let you monitor
various environmental properties. You can use these sensors to
monitor relative ambient humidity, illuminance, ambient pressure,
and ambient temperature near an Android-powered device.
All four environment sensors are hardware-based and are available
only if a device manufacturer has built them into a device. With the
exception of the light sensor, which most device manufacturers use to
control screen brightness, environment sensors are not always
available on devices.
Because of this, it's particularly important that you verify at runtime
whether an environment sensor exists before you attempt to acquire
data from it.
Unlike most motion sensors and position sensors, which return a
multi-dimensional array of sensor values for each SensorEvent(This
class represents a Sensor event and holds information such as the
sensor's type, the time-stamp, accuracy and of course the
sensor's data.), environment sensors return a single sensor value for
each data event.
For example, the temperature in °C or the pressure in hPa. Also, unlike
motion sensors and position sensors, which often require high-pass or
low-pass filtering, environment sensors do not typically require any
data filtering or data processing. Table 1 provides a summary of the
environment sensors that are supported on the Android platform.
Use the light, pressure, and temperature sensors :
The raw data you acquire from the light, pressure, and temperature sensors
usually requires no calibration, filtering, or modification, which makes them
some of the easiest sensors to use.
You can acquire raw relative humidity data by using the humidity sensor the
same way that you use the light, pressure, and temperature sensors.
However, if a device has both a humidity sensor
(TYPE_RELATIVE_HUMIDITY) and a temperature sensor
(TYPE_AMBIENT_TEMPERATURE) you can use these two data streams to
calculate the dew point and the absolute humidity.
Absolute humidity
The absolute humidity is the mass of water vapor in a given volume of dry
air. Absolute humidity is measured in grams/meter3. The following equation
shows how you can calculate the absolute humidity:
Where,
m = 17.62
Tn = 243.12 degrees C
A = 6.112 hPa
POSITIONAL SENSORS :
The Android platform provides two sensors that let you determine the
position of a device: the geomagnetic field sensor and the accelerometer.
The Android platform also provides a sensor that lets you determine how
close the face of a device is to an object (known as the proximity sensor).
The geomagnetic field sensor and the proximity sensor are hardware-based.
Most handset and tablet manufacturers include a geomagnetic field sensor.
Likewise, handset manufacturers usually include a proximity sensor to
determine when a handset is being held close to a user's face (for example,
during a phone call).
For determining a device's orientation, you can use the readings from the
device's accelerometer and the geomagnetic field sensor.
Because the game rotation vector sensor does not use the magnetic field,
relative rotations are more accurate, and not impacted by magnetic field
changes. Use this sensor in a game if you do not care about where north is,
and the normal rotation vector does not fit your needs because of its
reliance on the magnetic field.
The following code shows you how to get an instance of the default game
rotation vector sensor:
The following code shows you how to get an instance of the default
geomagnetic rotation vector sensor:
The geomagnetic field sensor lets you monitor changes in the earth's
magnetic field. The following code shows you how to get an instance of the
default geomagnetic field sensor:
The proximity sensor lets you determine how far away an object is from a
device. The following code shows you how to get an instance of the default
proximity sensor:
The proximity sensor is usually used to determine how far away a person's
head is from the face of a handset device (for example, when a user is
making or receiving a phone call). Most proximity sensors return the
absolute distance, in cm, but some return only near and far values.