Get access to every sensor present in the device!
Supported Android version: 21+
Supported iOS version: Not supported
Supported Browsers: Chromium-based
npm install @danyalwe/capacitor-sensors
npx cap sync
- Add support for iOS
Name | Android | iOS | Web |
---|---|---|---|
init | ✅ | ❌ | ✅ |
getAvailableSensors | ✅ | ❌ | ✅ |
start | ✅ | ❌ | ✅ |
stop | ✅ | ❌ | ✅ |
addListener | ✅ | ❌ | ✅ |
removeAllListeners | ✅ | ❌ | ✅ |
requestPermissions | ✅ | ❌ | ✅ |
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 |
✅ | ❌ | ❌ |
init(...)
getAvailableSensors()
requestPermissions(...)
start(...)
stop(...)
addListener(...)
removeAllListeners()
- Interfaces
- Type Aliases
- Enums
init(options: SensorOptions) => Promise<SensorData | undefined>
Param | Type |
---|---|
options |
SensorOptions |
Returns: Promise<SensorData>
getAvailableSensors() => Promise<{ sensors: SensorType[]; }>
Returns: Promise<{ sensors: SensorType[]; }>
requestPermissions(sensor: SensorData) => Promise<WebPermissionStatus>
Param | Type |
---|---|
sensor |
SensorData |
Returns: Promise<WebPermissionStatus>
start(sensor: SensorData) => Promise<void>
Param | Type |
---|---|
sensor |
SensorData |
stop(sensor: SensorData) => Promise<void>
Param | Type |
---|---|
sensor |
SensorData |
addListener(eventName: SensorEvent, listenerFunc: (event: SensorResult) => void) => Promise<PluginListenerHandle>
Param | Type |
---|---|
eventName |
SensorEvent |
listenerFunc |
(event: SensorResult) => void |
Returns: Promise<PluginListenerHandle>
removeAllListeners() => Promise<void>
Prop | Type |
---|---|
infos |
SensorInfos |
Prop | Type |
---|---|
vendor |
string |
version |
number |
type |
number |
maxRange |
number |
resolution |
number |
power |
number |
minDelay |
number |
maxDelay |
number |
Prop | Type |
---|---|
type |
SensorType |
delay |
SensorDelay |
Prop | Type |
---|---|
accelerometer |
PermissionState |
'ambient-light-sensor' |
PermissionState |
gyroscope |
PermissionState |
magnetometer |
PermissionState |
Prop | Type |
---|---|
remove |
() => Promise<void> |
Prop | Type |
---|---|
accuracy |
number |
timestamp |
number |
values |
number[] |
'prompt' | 'prompt-with-rationale' | 'granted' | 'denied'
keyof typeof 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 |
Members |
---|
FASTEST |
GAME |
UI |
NORMAL |