Nested Classes | ||
---|---|---|
interface | Sensor.Intents | Intents sent between extensions and host applications either using the broadcast queue or Tunnel. |
interface | Sensor.SensorRates | Interface used to define constants for sensor rates. |
interface | Sensor.SensorAccuracy | Interface used to define constants for sensor accuracy. |
interface | Sensor.SensorInterruptMode | Interface used to define constants for sensor interrupt mode. |
interface | Sensor.SensorApiErrorCodes | Interface used to define constants for sensor error codes sent from the host application |
Constants | ||
---|---|---|
java.lang.String | SENSOR_TYPE_ACCELEROMETER | Deprecated. |
java.lang.String | SENSOR_TYPE_LIGHT | Deprecated. |
Protected Constructors | |
---|---|
Sensor() |
Deprecated.
Constant defining the sensor type Accelerometer. Sensor data is sent as an array of 3 float values representing the acceleration on the x-axis, y-axis and z-axis respectively. All values are in SI units (m/s^2) For more information about the accelerometer sensor type, see TYPE_ACCELEROMETER
Constant Value: "Accelerometer"
Deprecated.
Constant defining the sensor type Light. Sensor data is sent as one float value representing the light level in SI lux units. For more information about the light sensor type, see TYPE_LIGHT
Constant Value: "Light"
Sensor API is a part of the Smart Extension APIs.
The Sensor API is used to send accessory sensor data from a host application to an accessory extension.
When a host application registers its capabilities, it will declare if it supports the Sensor API and what sensors it exposes. Extensions can use the Registration API to query host applications for supported sensors.
In order to use this API, an application must have registered itself properly in the registration content provider, see Registration API.
How to register a listener
Sensor data is sent over a LocalSocket. In order to start communication the extension should setup a LocalServerSocket android.net.LocalServerSocket in listening mode and send the SENSOR_REGISTER_LISTENER_INTENT intent. The Registration API can be used to query the host application for supported sensors. If multiple sensors are used, multiple LocalServerSocket objects must also be used since one sensor is bound to exactly one LocalServerSocket. When an extension registers a listener it also specifies what sample rate it wants to have.
Some sensors support interrupt mode. They can be configured to only send sensor data when new values are available. The interrupt flag is part of the sensor data registration Intent.
To unregister a listener the extension must send the SENSOR_UNREGISTER_LISTENER_INTENT.
Sensor data format
The sensor data is sent from the host application over a LocalSocket and can be accessed through an InputStream. The data has the following format: