Sensor framework:
- Determine which sensors are available
- What the sensor’s capabilities are
- Acquire raw sensor data
- Register/unregister sensor event listeners
Types:
TYPE_ACCELEROMETER- Acceleration in m/s^2
- Includes gravity
TYPE_AMBIENT_TEMPERATURE- Not common
- Room temperature in Celsius
TYPE_GRAVITY- Software sensor
TYPE_GYROSCOPE- Measures rate of rotation
TYPE_LIGHT- Light level in lux
TYPE_LINEAR_ACCELERATION- Excludes effect of gravity
TYPE_MAGNETIC_FIELD- Ambient geomagnetic field in three axes
- Measured in μT
TYPE_PRESSURE- Ambient air pressure in hPa
TYPE_PROXIMITY- Proximity of object
- Usually binary
TYPE_ROTATION_VECTOR- Orientation of device
Can Sensor capabilities:
- Minimum delay (in μS)
- Power consumption (in mA)
- Max range
- Resolution
Using sensor:
- Obtain
SensorManagerobject - Create
SensorEventListenerto listen toSensorEvents- Two methods
onAccuracyChanged(Sensor sensor, int accuracy)onSensorChanged(SensorEvent event)- When sensor value changing
- Should not do heavy computations in this method (or at least not on the same thread)
- Don’t hold on to the event: it is part of a pool of objects and so the values may be altered
- Two methods
- Register the listener
- Registration if for a specific sensor and sampling period
- The sampling period is a suggestion/hint
- Pre-defined constants:
SENSOR_DELAY_NORMAL,UI,GAME, orFASTEST
- Pre-defined constants:
- And unregister when done (e.g.
onPause)
Sensor coordinate system:
- X-axis: parallel to the x-axis of the screen in the device’s natural orientation (may be landscape for tablets)
- Y-axis: parallel to the y-axis of the screen in the device’s natural orientation
- Z: normal to the screen, positive pointing towards the user