0.2.0 • Published 6 years ago

cordova-plugin-android-sensor-listeners v0.2.0

Weekly downloads
11
License
MIT
Repository
github
Last release
6 years ago

Cordova Android Sensor Listeners Plugin

This plugin gives easy access to every available Android's sensors.

Install

cordova plugin add https://github.com/QuentinRoy/cordova-plugin-android-sensor-listeners.git

API: sensors

sensors.addSensorListener(sensorType, samplingPeriod, listener, callback) ⇒ undefined

Add a sensor listener.

Kind: static method of sensors

ParamTypeDescription
sensorTypestringThe sensor type's constant name (as defined by Android's Sensor, but without the prefix "TYPE_").
samplingPeriodstringThe sampling period's constant name (as accepted by SensorManager#registerListener, but without the prefix "SENSOR_DELAY_").
listenersensorEventListenerThe listener to register.
callbackerrorFirstCallbackA 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");
});

sensors.removeSensorListener(sensorType, samplingPeriod, listener, callback) ⇒ undefined

Remove a sensor listener.

Kind: static method of sensors

ParamTypeDescription
sensorTypestringThe type of the sensor as registered when the listener was added (see addSensorListener).
samplingPeriodstringThe sampling period as registered when the listener was added (see addSensorListener).
listenersensorEventListenerThe listener to remove.
callbackerrorFirstCallbackA 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");
});

SensorEvent : Object

Event emitted from sensors.

Kind: global typedef
Properties

NameTypeDescription
sensorstringThe type of sensor that is listened to.
samplingstringThe sampling period the sensor is listened to by the receiving event listener.
timeStampintThe time the event was emitted.
valuesArray.<float>The sensor values.

errorFirstCallback : function

This callback is used to get responses from async calls. It complies with nodeJS callback style.

Kind: global typedef

ParamTypeDescription
err*the error or undefined if everything went fine
data*the response or the called function

sensorEventListener : function

This listener is used to receive events from sensors.

Kind: global typedef

ParamTypeDescription
evtSensorEventthe event emitted by one of the sensor