@capawesome-team/capacitor-accelerometer¶
Capacitor plugin to capture the acceleration force along the x, y, and z axes.
Features¶
We are proud to offer one of the most complete and feature-rich Capacitor plugins for accelerometer measurements. Here are some of the key features:
- 🖥️ Cross-platform: Supports Android and iOS.
- ⚡ Real-time measurements: Continuous accelerometer data with event listeners.
- 📊 High precision: Accurate x, y, and z-axis acceleration measurements in G's.
- 🔒 Permission handling: Built-in permission management for sensor access.
- 📦 SPM: Supports Swift Package Manager for iOS.
- 🔁 Up-to-date: Always supports the latest Capacitor version.
- ⭐️ Support: Priority support from the Capawesome Team.
Missing a feature? Just open an issue and we'll take a look!
Compatibility¶
Plugin Version | Capacitor Version | Status |
---|---|---|
7.x.x | >=7.x.x | Active support |
Installation¶
This plugin is only available to Capawesome Insiders. First, make sure you have the Capawesome npm registry set up. You can do this by running the following commands:
npm config set @capawesome-team:registry https://npm.registry.capawesome.io
npm config set //npm.registry.capawesome.io/:_authToken <YOUR_LICENSE_KEY>
Attention: Replace <YOUR_LICENSE_KEY>
with the license key you received from Polar. If you don't have a license key yet, you can get one by becoming a Capawesome Insider.
Next, install the package:
Android¶
Proguard¶
If you are using Proguard, you need to add the following rules to your proguard-rules.pro
file:
iOS¶
Privacy Descriptions¶
Add the NSMotionUsageDescription
key to the ios/App/App/Info.plist
file, which tells the user why your app needs access to the user's contacts:
Usage¶
import { Accelerometer } from '@capawesome-team/capacitor-accelerometer';
const getMeasurement = async () => {
const measurement = await Accelerometer.getMeasurement();
console.log("X: ", measurement.x);
console.log("Y: ", measurement.y);
console.log("Z: ", measurement.z);
};
const isAvailable = async () => {
const result = await Accelerometer.isAvailable();
return result.isAvailable;
};
const startMeasurementUpdates = async () => {
await Accelerometer.startMeasurementUpdates();
};
const stopMeasurementUpdates = async () => {
await Accelerometer.stopMeasurementUpdates();
};
const checkPermissions = async () => {
const result = await Accelerometer.checkPermissions();
return result;
};
const requestPermissions = async () => {
const result = await Accelerometer.requestPermissions();
return result;
};
const removeAllListeners = async () => {
await Accelerometer.removeAllListeners();
};
API¶
getMeasurement()
isAvailable()
startMeasurementUpdates()
stopMeasurementUpdates()
checkPermissions()
requestPermissions()
addListener('measurement', ...)
removeAllListeners()
- Interfaces
- Type Aliases
getMeasurement()¶
Get the latest measurement.
This method returns the most recent measurement from the accelerometer sensor.
Returns: Promise<Measurement>
Since: 0.1.0
isAvailable()¶
Check if the accelerometer sensor is available on the device.
Returns: Promise<IsAvailableResult>
Since: 0.1.0
startMeasurementUpdates()¶
Starts emitting measurement
events.
Since: 0.1.0
stopMeasurementUpdates()¶
Stops emitting measurement
events.
Since: 0.1.0
checkPermissions()¶
Check if the app has permission to access the accelerometer sensor.
Returns: Promise<PermissionStatus>
Since: 0.1.0
requestPermissions()¶
Request permission to access the accelerometer sensor.
Returns: Promise<PermissionStatus>
Since: 0.1.0
addListener('measurement', ...)¶
addListener(eventName: 'measurement', listenerFunc: (event: MeasurementEvent) => void) => Promise<PluginListenerHandle>
Only available on Android and iOS.
Param | Type |
---|---|
eventName |
'measurement' |
listenerFunc |
(event: Measurement) => void |
Returns: Promise<PluginListenerHandle>
Since: 0.1.0
removeAllListeners()¶
Remove all listeners for this plugin.
Since: 0.1.0
Interfaces¶
Measurement¶
Prop | Type | Description | Since |
---|---|---|---|
x |
number |
The x-axis acceleration in G's (gravitational force). | 0.1.0 |
y |
number |
The y-axis acceleration in G's (gravitational force). | 0.1.0 |
z |
number |
The z-axis acceleration in G's (gravitational force). | 0.1.0 |
IsAvailableResult¶
Prop | Type | Description | Since |
---|---|---|---|
isAvailable |
boolean |
Whether the accelerometer sensor is available on the device. | 0.1.0 |
PermissionStatus¶
Prop | Type | Description | Since |
---|---|---|---|
accelerometer |
AccelerometerPermissionState |
The permission status of accelerometer. | 0.1.0 |
PluginListenerHandle¶
Prop | Type |
---|---|
remove |
() => Promise<void> |
Type Aliases¶
GetMeasurementResult¶
AccelerometerPermissionState¶
PermissionState | 'limited'
PermissionState¶
'prompt' | 'prompt-with-rationale' | 'granted' | 'denied'
MeasurementEvent¶
Changelog¶
See CHANGELOG.md.
Breaking Changes¶
See BREAKING.md.
License¶
See LICENSE.