@capawesome-team/capacitor-pedometer¶
Capacitor plugin to retrieve motion data, such as the number of steps and other information about the distance traveled.
Features¶
We are proud to offer one of the most complete and feature-rich Capacitor plugins for pedometer data. Here are some of the key features:
- 🖥️ Cross-platform: Supports Android and iOS.
- 🚶 Motion Tracking: Retrieve step count, distance, pace, cadence, and floor counting data.
- 📊 Real-time Updates: Stream live pedometer data with event listeners for continuous monitoring.
- 📅 Historical Data: Query pedometer measurements for specific time ranges and periods.
- 🔍 Feature Detection: Check device capability for different pedometer features (steps, distance, floors, etc.).
- 📦 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 { Pedometer } from '@capawesome-team/capacitor-pedometer';
const getMeasurement = async () => {
const { measurement } = await Pedometer.getMeasurement();
console.log(measurement);
};
const isAvailable = async () => {
const { cadence, distance, floorCounting, pace, stepCounting } = await Pedometer.isAvailable();
console.log('Cadence available:', cadence);
console.log('Distance available:', distance);
console.log('Floor counting available:', floorCounting);
console.log('Pace available:', pace);
console.log('Step counting available:', stepCounting);
};
const startMeasurementUpdates = async () => {
Pedometer.addListener('measurement', (event) => {
console.log('New measurement:', event);
});
await Pedometer.startMeasurementUpdates();
};
const stopMeasurementUpdates = async () => {
await Pedometer.stopMeasurementUpdates();
};
const checkPermissions = async () => {
const status = await Pedometer.checkPermissions();
console.log('Permission status:', status);
};
const requestPermissions = async () => {
const status = await Pedometer.requestPermissions();
console.log('Permission status after request:', status);
};
API¶
getMeasurement(...)
isAvailable()
startMeasurementUpdates()
stopMeasurementUpdates()
checkPermissions()
requestPermissions()
addListener('measurement', ...)
removeAllListeners()
- Interfaces
- Type Aliases
getMeasurement(...)¶
Retrieve the pedometer data (for a specific time range).
Only available on Android and iOS.
Param | Type |
---|---|
options |
GetMeasurementOptions |
Returns: Promise<Measurement>
Since: 7.0.0
isAvailable()¶
Check which features are available on the device.
Returns: Promise<IsAvailableResult>
Since: 7.0.0
startMeasurementUpdates()¶
Start receiving updates for the pedometer data.
Only available on Android and iOS.
Since: 7.0.0
stopMeasurementUpdates()¶
Stop receiving updates for the pedometer data.
Only available on Android and iOS.
Since: 7.0.0
checkPermissions()¶
Check permissions for the plugin.
Returns: Promise<PermissionStatus>
Since: 7.0.0
requestPermissions()¶
Request permissions for the plugin.
Returns: Promise<PermissionStatus>
Since: 7.0.0
addListener('measurement', ...)¶
addListener(eventName: 'measurement', listenerFunc: (event: MeasurementEvent) => void) => Promise<PluginListenerHandle>
Called when the pedometer data is updated.
When the app is suspended, the delivery of updates stops temporarily. When the app is resumed, the updates will continue from where they left off.
Note: The startMeasurementUpdates
method must be called
before this event can be received.
Only available on Android and iOS.
Param | Type |
---|---|
eventName |
'measurement' |
listenerFunc |
(event: Measurement) => void |
Returns: Promise<PluginListenerHandle>
Since: 6.0.0
removeAllListeners()¶
Remove all listeners for this plugin.
Since: 7.0.0
Interfaces¶
Measurement¶
Prop | Type | Description | Since |
---|---|---|---|
averageActivePace |
number |
The average pace of the user, measured in seconds per meter. Only available on iOS. | 7.0.0 |
currentCadence |
number |
The rate at which steps are taken, measured in steps per second. Only available on iOS. | 7.0.0 |
currentPace |
number |
The current pace of the user, measured in seconds per meter. Only available on iOS. | 7.0.0 |
distance |
number |
The estimated distance traveled by the user, measured in meters. Only available on iOS. | 7.0.0 |
end |
number |
The end date of the data in milliseconds since epoch. | 7.0.0 |
floorsAscended |
number |
The number of floors ascended by the user. Only available on iOS. | 7.0.0 |
floorsDescended |
number |
The number of floors descended by the user. Only available on iOS. | 7.0.0 |
numberOfSteps |
number |
The number of steps taken by the user. | 7.0.0 |
start |
number |
The start date of the data in milliseconds since epoch. | 7.0.0 |
GetMeasurementOptions¶
Prop | Type | Description | Since |
---|---|---|---|
end |
number |
The end date for the query in milliseconds since epoch. On iOS, this option must be provided. Only available on iOS. | 7.0.0 |
start |
number |
The start date for the query in milliseconds since epoch. On Android, this is always set to the boot time of the device. On iOS, this option must be provided. Only available on iOS. | 7.0.0 |
IsAvailableResult¶
Prop | Type | Description | Since |
---|---|---|---|
cadence |
boolean |
Indicates whether cadence tracking is available on the device. On Android, this is always false because cadence tracking is not supported. |
7.0.0 |
distance |
boolean |
Indicates whether distance tracking is available on the device. On Android, this is always false because distance tracking is not supported. |
7.0.0 |
floorCounting |
boolean |
Indicates whether floor counting is available on the device. On Android, this is always false because floor counting is not supported. |
7.0.0 |
pace |
boolean |
Indicates whether pace tracking is available on the device. On Android, this is always false because pace tracking is not supported. |
7.0.0 |
stepCounting |
boolean |
Indicates whether step counting is available on the device. | 7.0.0 |
PermissionStatus¶
Prop | Type | Description | Since |
---|---|---|---|
activityRecognition |
PermissionState |
The permission state for the activity recognition feature. | 7.0.0 |
PluginListenerHandle¶
Prop | Type |
---|---|
remove |
() => Promise<void> |
Type Aliases¶
GetMeasurementResult¶
PermissionState¶
'prompt' | 'prompt-with-rationale' | 'granted' | 'denied'
MeasurementEvent¶
Changelog¶
See CHANGELOG.md.
Breaking Changes¶
See BREAKING.md.
License¶
See LICENSE.