https://github.com/cap-go/capacitor-pedometer
Capacitor plugin for accessing pedometer data including steps, distance, pace, cadence, and floors
https://github.com/cap-go/capacitor-pedometer
Last synced: about 2 months ago
JSON representation
Capacitor plugin for accessing pedometer data including steps, distance, pace, cadence, and floors
- Host: GitHub
- URL: https://github.com/cap-go/capacitor-pedometer
- Owner: Cap-go
- License: mpl-2.0
- Created: 2025-10-27T07:00:46.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2026-04-06T06:22:08.000Z (2 months ago)
- Last Synced: 2026-04-06T08:41:19.322Z (2 months ago)
- Language: JavaScript
- Size: 611 KB
- Stars: 7
- Watchers: 0
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Agents: AGENTS.md
Awesome Lists containing this project
README
# @capgo/capacitor-pedometer
Capacitor plugin for accessing pedometer data including steps, distance, pace, cadence, and floors.
## Compatibility
| Plugin version | Capacitor compatibility | Maintained |
| -------------- | ----------------------- | ---------- |
| v8.\*.\* | v8.\*.\* | ✅ |
| v7.\*.\* | v7.\*.\* | On demand |
| v6.\*.\* | v6.\*.\* | ❌ |
| v5.\*.\* | v5.\*.\* | ❌ |
> **Note:** The major version of this plugin follows the major version of Capacitor. Use the version that matches your Capacitor installation (e.g., plugin v8 for Capacitor 8). Only the latest major version is actively maintained.
## Install
```bash
npm install @capgo/capacitor-pedometer
npx cap sync
```
## Configuration
### iOS
Add the following to your `Info.plist`:
```xml
NSMotionUsageDescription
We need access to your motion data to track steps and activity
```
### Android
The plugin will automatically add the `ACTIVITY_RECOGNITION` permission to your `AndroidManifest.xml`.
For Android 10 (API 29) and above, you need to request the `ACTIVITY_RECOGNITION` permission at runtime.
## API
* [`getMeasurement(...)`](#getmeasurement)
* [`isAvailable()`](#isavailable)
* [`startMeasurementUpdates()`](#startmeasurementupdates)
* [`stopMeasurementUpdates()`](#stopmeasurementupdates)
* [`checkPermissions()`](#checkpermissions)
* [`requestPermissions()`](#requestpermissions)
* [`addListener('measurement', ...)`](#addlistenermeasurement-)
* [`removeAllListeners()`](#removealllisteners)
* [`getPluginVersion()`](#getpluginversion)
* [Interfaces](#interfaces)
* [Type Aliases](#type-aliases)
### getMeasurement(...)
```typescript
getMeasurement(options?: GetMeasurementOptions | undefined) => Promise
```
Get pedometer measurements for a specified time range.
| Param | Type |
| ------------- | ----------------------------------------------------------------------- |
| **`options`** | GetMeasurementOptions |
**Returns:** Promise<Measurement>
**Since:** 0.0.1
--------------------
### isAvailable()
```typescript
isAvailable() => Promise
```
Check which pedometer features are available on this device.
**Returns:** Promise<IsAvailableResult>
**Since:** 0.0.1
--------------------
### startMeasurementUpdates()
```typescript
startMeasurementUpdates() => Promise
```
Start receiving real-time pedometer measurement updates.
On **Android** and **iOS**, the `measurement` event is only fired after calling `startMeasurementUpdates()`.
**Since:** 0.0.1
--------------------
### stopMeasurementUpdates()
```typescript
stopMeasurementUpdates() => Promise
```
Stop receiving real-time pedometer measurement updates.
**Since:** 0.0.1
--------------------
### checkPermissions()
```typescript
checkPermissions() => Promise
```
Check permission to access pedometer data.
On **Android**, this checks the `ACTIVITY_RECOGNITION` permission.
On **iOS**, this checks the motion usage permission.
**Returns:** Promise<PermissionStatus>
**Since:** 0.0.1
--------------------
### requestPermissions()
```typescript
requestPermissions() => Promise
```
Request permission to access pedometer data.
On **Android**, this requests the `ACTIVITY_RECOGNITION` permission.
On **iOS**, this requests motion usage permission.
**Returns:** Promise<PermissionStatus>
**Since:** 0.0.1
--------------------
### addListener('measurement', ...)
```typescript
addListener(eventName: 'measurement', listenerFunc: (event: MeasurementEvent) => void) => Promise
```
Called when a new pedometer measurement is received.
| Param | Type |
| ------------------ | ----------------------------------------------------------------------- |
| **`eventName`** | 'measurement' |
| **`listenerFunc`** | (event: Measurement) => void |
**Returns:** Promise<PluginListenerHandle>
**Since:** 0.0.1
--------------------
### removeAllListeners()
```typescript
removeAllListeners() => Promise
```
Remove all listeners for this plugin.
**Since:** 0.0.1
--------------------
### getPluginVersion()
```typescript
getPluginVersion() => Promise<{ version: string; }>
```
Get the native Capacitor plugin version.
**Returns:** Promise<{ version: string; }>
**Since:** 1.0.0
--------------------
### Interfaces
#### Measurement
| Prop | Type | Description | Since |
| ----------------------- | ------------------- | ----------------------------------------------------------------------------------- | ----- |
| **`numberOfSteps`** | number | The number of steps taken by the user. | 0.0.1 |
| **`distance`** | number | The estimated distance (in meters) traveled by the user. Only available on **iOS**. | 0.0.1 |
| **`floorsAscended`** | number | The approximate number of floors ascended. Only available on **iOS**. | 0.0.1 |
| **`floorsDescended`** | number | The approximate number of floors descended. Only available on **iOS**. | 0.0.1 |
| **`currentPace`** | number | The current pace (in seconds per meter). Only available on **iOS**. | 0.0.1 |
| **`currentCadence`** | number | The current cadence (steps per second). Only available on **iOS**. | 0.0.1 |
| **`averageActivePace`** | number | The average active pace (in seconds per meter). Only available on **iOS**. | 0.0.1 |
| **`startDate`** | number | The start time of this measurement (milliseconds since epoch). | 0.0.1 |
| **`endDate`** | number | The end time of this measurement (milliseconds since epoch). | 0.0.1 |
#### GetMeasurementOptions
| Prop | Type | Description | Since |
| ----------- | ------------------- | ----------------------------------------------------------------------------------------- | ----- |
| **`start`** | number | The start time for the measurement query (milliseconds since epoch). Required on **iOS**. | 0.0.1 |
| **`end`** | number | The end time for the measurement query (milliseconds since epoch). Required on **iOS**. | 0.0.1 |
#### IsAvailableResult
| Prop | Type | Description | Since |
| ------------------- | -------------------- | --------------------------------------------------------------------------------------------------------- | ----- |
| **`stepCounting`** | boolean | Whether step counting is available. | 0.0.1 |
| **`distance`** | boolean | Whether distance measurement is available. Only `true` on **iOS** devices that support distance tracking. | 0.0.1 |
| **`pace`** | boolean | Whether pace measurement is available. Only `true` on **iOS** devices that support pace tracking. | 0.0.1 |
| **`cadence`** | boolean | Whether cadence measurement is available. Only `true` on **iOS** devices that support cadence tracking. | 0.0.1 |
| **`floorCounting`** | boolean | Whether floor counting is available. Only `true` on **iOS** devices that support floor tracking. | 0.0.1 |
#### PermissionStatus
| Prop | Type | Description | Since |
| ------------------------- | ------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
| **`activityRecognition`** | 'prompt' \| 'prompt-with-rationale' \| 'granted' \| 'denied' | Permission state for activity recognition. On **Android**, this is the `ACTIVITY_RECOGNITION` permission. On **iOS**, this is the motion usage permission. | 0.0.1 |
#### PluginListenerHandle
| Prop | Type |
| ------------ | ----------------------------------------- |
| **`remove`** | () => Promise<void> |
### Type Aliases
#### MeasurementEvent
## Usage
```typescript
import { CapacitorPedometer } from '@capgo/capacitor-pedometer';
// Check availability
const availability = await CapacitorPedometer.isAvailable();
console.log('Features available:', availability);
// Check and request permissions
const permission = await CapacitorPedometer.checkPermissions();
if (permission.activityRecognition !== 'granted') {
await CapacitorPedometer.requestPermissions();
}
// Start real-time updates
await CapacitorPedometer.addListener('measurement', (data) => {
console.log('Steps:', data.numberOfSteps);
console.log('Distance:', data.distance);
});
await CapacitorPedometer.startMeasurementUpdates();
// Query historical data (iOS only - requires start and end timestamps)
const now = Date.now();
const yesterday = now - (24 * 60 * 60 * 1000);
const measurement = await CapacitorPedometer.getMeasurement({
start: yesterday,
end: now
});
// Stop updates
await CapacitorPedometer.stopMeasurementUpdates();
await CapacitorPedometer.removeAllListeners();
```
## Platform Support
| Feature | Android | iOS |
|---------|---------|-----|
| Step Counting | ✅ | ✅ |
| Distance | ❌ | ✅ |
| Pace | ❌ | ✅ |
| Cadence | ❌ | ✅ |
| Floor Counting | ❌ | ✅ |
| Historical Queries | ❌ | ✅ |
## Notes
- On **Android**, only step counting is available. The plugin uses the `TYPE_STEP_COUNTER` sensor.
- On **iOS**, all features are available on supported devices using `CMPedometer`.
- Historical data queries require explicit `start` and `end` timestamps on iOS.
- Android's step counter gives cumulative steps since last device reboot; the plugin tracks the delta.
- Measurements are paused when the app is in the background.
## License
MIT