Documente Academic
Documente Profesional
Documente Cultură
1. Sensors
2. Monitoring
the Battery
1
1. Sensors
The emulator does not provide any sensor data. All sensor
testing must be done on a physical device. Alternatively,
OpenIntents.org also provides a handy Sensor Simulator:
http://code.google.com/p/openintents/wiki/SensorSimulator
This tool simulates accelerometer, compass, and
temperature sensors, and it transmits data to the emulator.
Android devices have a variety of sensors :
1. Sensors
TYPE_ACCELEROMETER: Measures acceleration in three
directions; values are in SI units (m/s2).
TYPE_GYROSCOPE: Measures angular orientation in three
directions; values are angles in degrees.
TYPE_LIGHT: Measures ambient light; values are in SI lux
units.
TYPE_MAGNETIC_FIELD: Measures magnetism in three
directions; the compass values are in micro-Tesla (uT).
TYPE_PRESSURE: Measures barometric pressure.
TYPE_PROXIMITY: Measures the distance to an object;
values are in centimeters, or near versus far.
TYPE_RELATIVE_HUMIDITY: Measures the relative humidity.
TYPE_AMBIENT_TEMPERATURE: Measures temperature.
3
1. Sensors
Here are the major classes related to sensor.
Class
Sensor
Comment
SensorEventLis
tener
1. Sensors
1. Sensors
1. Sensors
UnRegister EventListener.
1. Sensors
SensorManager.SENSOR_DELAY
Frequence
Comment
1. Sensors
Receive SensorEvent
Normally, onSensorChanged is the method in which
we need to put your sensor handle logic.
1. Sensors
SensorEvent
Type
Name
Comment
public int accuracy The accuracy of this event.
publicSensor sensor
public long timestam
p
public final values
float[]
1. Sensors
Sensor.TYPE_TEMPERATUR
E
11
1. Sensors
Sensor.TYPE_TEMPERATUR
E
12
1. Sensors
Sensor.TYPE_LIGHT
13
1. Sensors
Sensor.TYPE_LIGHT
14
1. Sensors
Sensor.TYPE_PRESSURE
15
1. Sensors
Sensor.TYPE_PRESSURE
16
1. Sensors
Sensor. TYPE_PROXIMITY
17
1. Sensors
Sensor. TYPE_PROXIMITY
18
1. Sensors
Sensor. TYPE_PROXIMITY
19
1. Sensors
Sensor.TYPE_ACCELER
OMETER
The accelerometer values are
represented in SI units
(m/s2). The device at right has the bottom of the device
screen pointing toward the center of gravity. Gravity on
Earth is 9.80665 m/s2.
All values are in SI units (m/s2)
values[0]: Acceleration minus Gx on
the x-axis
values[1]: Acceleration minus Gy on
the y-axis
values[2]: Acceleration minus Gz on
the z-axis
20
1. Sensors
Sensor.TYPE_ACCELER
Use to Accelerometer to OMETER
detect SHAKING
Device
21
1. Sensors
Sensor.TYPE_ACCELER
OMETER
22
1. Sensors
Sensor.TYPE_ACCELER
OMETER
23
1. Sensors
Sensor.TYPE_GYROSCO
PE
measure, or maintain, the orientation
of a device.
rate of rotation around a particular axis
24
1. Sensors
Sensor.TYPE_GYROSCO
PE
25
1. Sensors
Sensor.TYPE_GYROSCO
PE
26
1. Sensors
Sensor.TYPE_ORIENTATI
ON
All values are angles in degrees:
values[0]: Azimuth, angle between the
magnetic north direction and the y-axis,
around the z-axis (0 to 359). 0=North,
90=East, 180=South, 270=West
values[1]: Pitch, rotation around x-axis (-180
to 180), with positive values when the z-axis
moves toward the y-axis.
values[2]: Roll, rotation around y-axis (-90 to
90), with positive values when the x-axis
moves toward the z-axis.
27
1. Sensors
Sensor.TYPE_ORIENTATI
ON
28
1. Sensors
Exercise : Using Sensors Accelerometor and
Proximity to build an AlbumManager
application:
- Nice GUI to display Pictures
- When Device was shaken to Left open the
Previous Picture
- When Device was shaken to Right open the Next
Picture
- When Proximity is active and event.values[0]==0.0
Close the AlbumManager application
29
30
Emulator
Physical Device
31
32
33
34
END
35