This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.

Expo Pedometer iconExpo Pedometer

A library that provides access to the device's pedometer sensor.

Android
iOS
Included in Expo Go

Pedometer from expo-sensors uses the system step counter sensor for live updates, and the Recording API on Android/Core Motion on iOS for step history.

iOS keeps collecting step history automatically (up to seven days). On Android, step history requires the pedometerPlayServicesEnabled config plugin option, Google Play services Recording API support, and an active subscribeRecordingAsync() subscription. Unsubscribing makes previously collected history inaccessible, and Android retains up to 10 days since the latest subscription. The subscription helpers (subscribeRecordingAsync() / unsubscribeRecordingAsync()) are no-ops on iOS.

Installation

Terminal
- npx expo install expo-sensors
- yarn expo install expo-sensors
- pnpm expo install expo-sensors
- bun expo install expo-sensors

If you are installing this in an existing React Native app, make sure to install expo in your project.

Configuration in app config

You can configure Pedometer from expo-sensors using its built-in config plugin. The plugin allows you to configure properties that cannot be set at runtime and require building a new app binary to take effect.

Example app.json with config plugin

app.json
{ "expo": { "plugins": [ [ "expo-sensors", { "motionPermission": "Allow $(PRODUCT_NAME) to access your device motion", "pedometerPlayServicesEnabled": true } ] ] } }

Configurable properties

NameDefaultDescription
motionPermission"Allow $(PRODUCT_NAME) to access your device motion"
Only for: 
iOS

A string to set the NSMotionUsageDescription permission message or false to disable motion permissions.

pedometerPlayServicesEnabledfalse
Only for: 
Android

Whether to include the Google Play services libraries that step history needs. They increase the app size. Without them, isRecordingAvailableAsync() returns false, and getStepCountAsync() and subscribeRecordingAsync() reject with ERR_PEDOMETER_PLAY_SERVICES_NOT_LINKED.

Usage

Pedometer
import { useState, useEffect } from 'react'; import { Platform, StyleSheet, Text, View } from 'react-native'; import { Pedometer } from 'expo-sensors'; export default function App() { const [isPedometerAvailable, setIsPedometerAvailable] = useState('checking'); const [isPedometerHistoryAvailable, setIsPedometerHistoryAvailable] = useState('checking'); const [pastStepCount, setPastStepCount] = useState(0); const [currentStepCount, setCurrentStepCount] = useState(0); const subscribe = async () => { const isAvailable = await Pedometer.isAvailableAsync(); setIsPedometerAvailable(String(isAvailable)); const isHistoryAvailable = await Pedometer.isRecordingAvailableAsync(); setIsPedometerHistoryAvailable(String(isHistoryAvailable)); if (isHistoryAvailable) { if (Platform.OS === 'android') { await Pedometer.subscribeRecordingAsync(); } const end = new Date(); const start = new Date(); start.setDate(end.getDate() - 1); const pastStepCountResult = await Pedometer.getStepCountAsync(start, end); setPastStepCount(pastStepCountResult.steps); } if (isAvailable) { return Pedometer.watchStepCount(result => { setCurrentStepCount(result.steps); }); } }; useEffect(() => { const subscriptionPromise = subscribe(); return () => { subscriptionPromise.then(subscription => subscription?.remove()); }; }, []); return ( <View style={styles.container}> <Text>Pedometer.isAvailableAsync(): {isPedometerAvailable}</Text> <Text>Pedometer.isRecordingAvailableAsync(): {isPedometerHistoryAvailable}</Text> <Text>Steps taken in the last 24 hours: {pastStepCount}</Text> <Text>Walk! And watch this go up: {currentStepCount}</Text> </View> ); } const styles = StyleSheet.create({ container: { flex: 1, marginTop: 15, alignItems: 'center', justifyContent: 'center', }, });

API

import { Pedometer } from 'expo-sensors';

Methods

Pedometer.getPermissionsAsync()

Android
iOS

Checks user's permissions for accessing pedometer.

Returns:
Promise<PermissionResponse>

Pedometer.getStepCountAsync(start, end)

Android
iOS
ParameterTypeDescription
startDate

A date indicating the start of the range over which to measure steps.

endDate

A date indicating the end of the range over which to measure steps.


Get the step count between two dates.

As Apple documentation states:

As Android's documentation states:

On Android, call subscribeRecordingAsync() before querying step history and keep it active if you want the previous days to be available.

a promise that fulfills with a PedometerResult.

Pedometer.isAvailableAsync()

Android
iOS

Returns whether the pedometer is enabled on the device.

Returns:
Promise<boolean>

a promise that fulfills with a boolean, indicating whether the pedometer is available on this device.

Pedometer.isRecordingAvailableAsync()

Android
iOS

Check whether step history is supported on this device. On iOS, historical data is collected automatically (up to seven days).

Returns:
Promise<boolean>

a promise that fulfills with a boolean, indicating whether historical step count data is available on this device.

Pedometer.requestPermissionsAsync()

Android
iOS

Asks the user to grant permissions for accessing pedometer.

Returns:
Promise<PermissionResponse>

Pedometer.subscribeRecordingAsync()

Android

Subscribe to pedometer tracking. Step count will be tracked by Google Play Services Recording API, if available, until unsubscribed. Subsequent calls are safe and ignored.

As Android's documentation states:

Returns:
Promise<void>

a promise that fulfills when the subscription is successful.

Pedometer.unsubscribeRecordingAsync()

Android

Unsubscribe from pedometer tracking.

As Android's documentation states:

Returns:
Promise<void>

a promise that fulfills when the unsubscription is successful.

Pedometer.watchStepCount(callback)

Android
iOS
ParameterTypeDescription
callbackPedometerUpdateCallback

A callback that is invoked when new step count data is available. The callback is provided with a single argument that is PedometerResult.


Subscribe to pedometer updates.

Returns:
EventSubscription

a Subscription that enables you to call remove() when you would like to unsubscribe the listener.

Interfaces

Subscription

Android
iOS

A subscription object that allows to conveniently remove an event listener from the emitter.

Subscription Methods

remove()

Android
iOS

Removes an event listener for which the subscription has been created. After calling this function, the listener will no longer receive any events from the emitter.

Returns:
void

Types

PedometerResult

Android
iOS
PropertyTypeDescription
stepsnumber

Number of steps taken between the given dates.

PedometerUpdateCallback(result)

Android
iOS

Callback function providing event result as an argument.

ParameterType
resultPedometerResult
Returns:

void

PermissionExpiration

Android
iOS

Literal type: union

Permission expiration time. Currently, all permissions are granted permanently.

Acceptable values are: 'never' | number

PermissionResponse

Android
iOS

An object obtained by permissions get and request functions.

PropertyTypeDescription
canAskAgainboolean

Indicates if user can be asked again for specific permission. If not, one should be directed to the Settings app in order to enable/disable the permission.

expiresPermissionExpiration

Determines time when the permission expires.

grantedboolean

A convenience boolean that indicates if the permission is granted.

statusPermissionStatus

Determines the status of the permission.

Enums

PermissionStatus

Android
iOS

DENIED

PermissionStatus.DENIED = "denied"

User has denied the permission.

GRANTED

PermissionStatus.GRANTED = "granted"

User has granted the permission.

UNDETERMINED

PermissionStatus.UNDETERMINED = "undetermined"

User hasn't granted or denied the permission yet.

Reference version