Skip to main content
Glama
pedometer.md1.84 kB
--- title: Pedometer description: A library that provides access to the device's pedometer sensor. sourceCodeUrl: https://github.com/expo/expo/tree/sdk-51/packages/expo-sensors packageName: expo-sensors iconUrl: /static/images/packages/expo-sensors.png platforms: ["android", "ios"] --- `Pedometer` from `expo-sensors` uses the system `hardware.Sensor` on Android and Core Motion on iOS to get the user's step count, and also allows you to subscribe to pedometer updates. ## Installation ## Usage ```jsx const [isPedometerAvailable, setIsPedometerAvailable] = useState('checking'); const [pastStepCount, setPastStepCount] = useState(0); const [currentStepCount, setCurrentStepCount] = useState(0); const subscribe = async () => { const isAvailable = await Pedometer.isAvailableAsync(); setIsPedometerAvailable(String(isAvailable)); if (isAvailable) { const end = new Date(); const start = new Date(); start.setDate(end.getDate() - 1); const pastStepCountResult = await Pedometer.getStepCountAsync(start, end); if (pastStepCountResult) { setPastStepCount(pastStepCountResult.steps); } return Pedometer.watchStepCount(result => { setCurrentStepCount(result.steps); }); } }; useEffect(() => { const subscription = subscribe(); return () => subscription && subscription.remove(); }, []); return ( <View style={styles.container}> <Text>Pedometer.isAvailableAsync(): {isPedometerAvailable}</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 ```js ```

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/jaksm/expo-docs-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server