
Security News
Crates.io Users Targeted by Phishing Emails
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
@danyalwe/capacitor-sensors
Advanced tools
Get access to every sensor present in the device!
Supported Android version: 23+
Supported iOS version: Not supported
Supported Browsers: Chromium-based
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" />
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' })
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 | ✅ | ❌ | ❌ |
The Sensors Plugin interface.
Represents the options for a sensor.
Prop | Type | Description |
---|---|---|
type | SensorType | The type of sensor to use. |
delay | SensorDelay | The delay between sensor readings. |
Represents the data returned by a sensor, including any additional information about the sensor.
Prop | Type |
---|---|
infos | 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. |
Interface representing the permission status for various web sensors.
Prop | Type |
---|---|
accelerometer | PermissionState |
'ambient-light-sensor' | PermissionState |
gyroscope | PermissionState |
magnetometer | PermissionState |
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. |
Prop | Type |
---|---|
remove | () => any |
(typeof SensorTypes)[number]
(typeof SensorDelays)[number]
'prompt' | 'prompt-with-rationale' | 'granted' | 'denied'
FAQs
Get access to every sensor present in the device!
We found that @danyalwe/capacitor-sensors demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.