npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@danyalwe/capacitor-sensors

v1.0.1

Published

Get access to every sensor present in the device!

Downloads

93

Readme

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

| 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

The Sensors Plugin interface.

Interfaces

SensorOptions

Represents the options for a sensor.

| Prop | Type | Description | | ----------- | --------------------------------------------------- | ---------------------------------- | | type | SensorType | The type of sensor to use. | | delay | SensorDelay | The delay between sensor readings. |

SensorData

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

| Prop | Type | | ----------- | --------------------------------------------------- | | infos | SensorInfos |

SensorInfos

Interface representing sensor information.

| Prop | Type | Description | | ---------------- | ------------------- | ---------------------------------------------------------- | | name | string | The name of the sensor. | | vendor | string | The vendor of the sensor. | | version | number | The version of the sensor. | | type | number | The type of the sensor. | | maxRange | number | The maximum range of the sensor in sensor units. | | resolution | number | The resolution of the sensor in sensor units. | | power | number | The power consumption of the sensor in milliamperes. | | minDelay | number | The minimum delay between sensor readings in microseconds. | | maxDelay | number | The maximum delay between sensor readings in microseconds. |

PermissionStatus

Interface representing the permission status for various web sensors.

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

SensorResult

Represents the result of a sensor reading.

| Prop | Type | Description | | --------------- | ------------------- | -------------------------------------------------- | | accuracy | number | The accuracy of the sensor reading, if available. | | timestamp | number | The timestamp of the sensor reading, if available. | | values | {} | The values obtained from the sensor reading. |

PluginListenerHandle

| Prop | Type | | ------------ | ------------------------- | | remove | () => any |

Type Aliases

SensorType

(typeof SensorTypes)[number]

SensorDelay

(typeof SensorDelays)[number]

PermissionState

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