Skip to content

zAlweNy26/capacitor-sensors

Repository files navigation

Capacitor Plugin - Sensors

Get access to every sensor present in the device!

Supported Android version: 21+
Supported iOS version: Not supported
Supported Browsers: Chromium-based

Install

npm install @danyalwe/capacitor-sensors
npx cap sync

Todos

  • Add support for iOS

Supported methods

Name Android iOS Web
init
getAvailableSensors
start
stop
addListener
removeAllListeners
requestPermissions

Supported sensors

Sensors Android iOS Web
MOTION_DETECTOR
LINEAR_ACCELERATION
MAGNETOMETER
GRAVITY
GYROSCOPE
AMBIENT_LIGHT
ACCELEROMETER
ABSOLUTE_ORIENTATION
RELATIVE_ORIENTATION
TEMPERATURE
GAME_ROTATION_VECTOR
GEOMAGNETIC_ROTATION_VECTOR
HEART_BEAT
HEART_RATE
POSE_6DOF
PRESSURE
PROXIMITY
RELATIVE_HUMIDITY
ROTATION_VECTOR
SIGNIFICANT_MOTION
STATIONARY_DETECTOR
STEP_COUNTER
STEP_DETECTOR

API

init(...)

init(options: SensorOptions) => Promise<SensorData | undefined>
Param Type
options SensorOptions

Returns: Promise<SensorData>


getAvailableSensors()

getAvailableSensors() => Promise<{ sensors: SensorType[]; }>

Returns: Promise<{ sensors: SensorType[]; }>


requestPermissions(...)

requestPermissions(sensor: SensorData) => Promise<WebPermissionStatus>
Param Type
sensor SensorData

Returns: Promise<WebPermissionStatus>


start(...)

start(sensor: SensorData) => Promise<void>
Param Type
sensor SensorData

stop(...)

stop(sensor: SensorData) => Promise<void>
Param Type
sensor SensorData

addListener(...)

addListener(eventName: SensorEvent, listenerFunc: (event: SensorResult) => void) => Promise<PluginListenerHandle>
Param Type
eventName SensorEvent
listenerFunc (event: SensorResult) => void

Returns: Promise<PluginListenerHandle>


removeAllListeners()

removeAllListeners() => Promise<void>

Interfaces

SensorData

Prop Type
infos SensorInfos

SensorInfos

Prop Type
vendor string
version number
type number
maxRange number
resolution number
power number
minDelay number
maxDelay number

SensorOptions

Prop Type
type SensorType
delay SensorDelay

WebPermissionStatus

Prop Type
accelerometer PermissionState
'ambient-light-sensor' PermissionState
gyroscope PermissionState
magnetometer PermissionState

PluginListenerHandle

Prop Type
remove () => Promise<void>

SensorResult

Prop Type
accuracy number
timestamp number
values number[]

Type Aliases

PermissionState

'prompt' | 'prompt-with-rationale' | 'granted' | 'denied'

SensorEvent

keyof typeof SensorType

Enums

SensorType

Members
AMBIENT_LIGHT
ACCELEROMETER
TEMPERATURE
GAME_ROTATION_VECTOR
GEOMAGNETIC_ROTATION_VECTOR
GRAVITY
GYROSCOPE
HEART_BEAT
HEART_RATE
LINEAR_ACCELERATION
MAGNETOMETER
MOTION_DETECTOR
POSE_6DOF
PRESSURE
PROXIMITY
RELATIVE_HUMIDITY
ROTATION_VECTOR
SIGNIFICANT_MOTION
STATIONARY_DETECTOR
STEP_COUNTER
STEP_DETECTOR
ABSOLUTE_ORIENTATION
RELATIVE_ORIENTATION

SensorDelay

Members
FASTEST
GAME
UI
NORMAL