Socket
Book a DemoInstallSign in
Socket

@danyalwe/capacitor-sensors

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@danyalwe/capacitor-sensors

Get access to every sensor present in the device!

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

Capacitor Plugin - Sensors

Get access to every sensor present in the device!

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

Install

npm install @danyalwe/capacitor-sensors
npx cap sync

If you want to use the HEART_BEAT or HEART_RATE sensor, you need to request the BODY_SENSORS permission in your app:

<uses-permission android:name="android.permission.BODY_SENSORS" />

If you want to use the STEP_COUNTER or STEP_DETECTOR sensor, you need to request the ACTIVITY_RECOGNITION permission in your app:

<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />

Example

The following example demonstrates how to use the Sensors plugin to access the device's accelerometer:

import { Sensors } from '@danyalwe/capacitor-sensors'

// Initialize the specific sensor and obtain infos about it
const sensor = await Sensors.init({ type: 'ACCELEROMETER' })

// Start the sensor to begin receiving data
await Sensors.start({ type: 'ACCELEROMETER' })

// Add a listener to receive accelerometer data
Sensors.addListener('ACCELEROMETER', (data) => {
  console.log('Accelerometer data:', data)
})

// Stop the sensor
await Sensors.stop({ type: 'ACCELEROMETER' })

Todos

  • Add support for iOS

Supported methods

NameAndroidiOSWeb
init
getAvailableSensors
start
stop
addListener
removeAllListeners
requestPermissions

Supported sensors

SensorsAndroidiOSWeb
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

  • Interfaces
  • Type Aliases

The Sensors Plugin interface.

Interfaces

SensorOptions

Represents the options for a sensor.

PropTypeDescription
typeSensorTypeThe type of sensor to use.
delaySensorDelayThe delay between sensor readings.

SensorData

Represents the data returned by a sensor, including any additional information about the sensor.

PropType
infosSensorInfos

SensorInfos

Interface representing sensor information.

PropTypeDescription
namestringThe name of the sensor.
vendorstringThe vendor of the sensor.
versionnumberThe version of the sensor.
typenumberThe type of the sensor.
maxRangenumberThe maximum range of the sensor in sensor units.
resolutionnumberThe resolution of the sensor in sensor units.
powernumberThe power consumption of the sensor in milliamperes.
minDelaynumberThe minimum delay between sensor readings in microseconds.
maxDelaynumberThe maximum delay between sensor readings in microseconds.

PermissionStatus

Interface representing the permission status for various web sensors.

PropType
accelerometerPermissionState
'ambient-light-sensor'PermissionState
gyroscopePermissionState
magnetometerPermissionState

SensorResult

Represents the result of a sensor reading.

PropTypeDescription
accuracynumberThe accuracy of the sensor reading, if available.
timestampnumberThe timestamp of the sensor reading, if available.
values{}The values obtained from the sensor reading.

PluginListenerHandle

PropType
remove() => any

Type Aliases

SensorType

(typeof SensorTypes)[number]

SensorDelay

(typeof SensorDelays)[number]

PermissionState

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

Keywords

capacitor

FAQs

Package last updated on 02 Sep 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts