This plugin gives easy access to every available Android's sensors.
cordova plugin add https://github.com/QuentinRoy/cordova-plugin-android-sensor-listeners.git
- sensors :
object
Add a sensor listener.
Kind: static method of sensors
Param | Type | Description |
---|---|---|
sensorType | string |
The sensor type's constant name (as defined by Android's Sensor, but without the prefix "TYPE_" ). |
samplingPeriod | string |
The sampling period's constant name (as accepted by SensorManager#registerListener, but without the prefix "SENSOR_DELAY_" ). |
listener | sensorEventListener |
The listener to register. |
[callback] | errorFirstCallback |
A node-style callback to be called upon success or failure of the operation. |
Example
function listener(event) {
console.log("device's rotation is " + event.values.join(","));
}
sensors.addSensorListener("ROTATION_VECTOR", "GAME", listener, function(error) {
if (error) console.error("Could not listen to sensor");
});
Remove a sensor listener.
Kind: static method of sensors
Param | Type | Description |
---|---|---|
sensorType | string |
The type of the sensor as registered when the listener was added (see addSensorListener). |
samplingPeriod | string |
The sampling period as registered when the listener was added (see addSensorListener). |
listener | sensorEventListener |
The listener to remove. |
[callback] | errorFirstCallback |
A node-style callback to be called upon success or failure of the operation. |
Example
sensors.removeSensorListener("ROTATION_VECTOR", "GAME", listener, function(error) {
if (error) console.error("Could not stop listening to sensor");
});
Event emitted from sensors.
Kind: global typedef
Properties
Name | Type | Description |
---|---|---|
sensor | string |
The type of sensor that is listened to. |
sampling | string |
The sampling period the sensor is listened to by the receiving event listener. |
timeStamp | int |
The time the event was emitted. |
values | Array.<float> |
The sensor values. |
This callback is used to get responses from async calls. It complies with nodeJS callback style.
Kind: global typedef
Param | Type | Description |
---|---|---|
[err] | * |
the error or undefined if everything went fine |
data | * |
the response or the called function |
This listener is used to receive events from sensors.
Kind: global typedef
Param | Type | Description |
---|---|---|
evt | SensorEvent |
the event emitted by one of the sensor |