Pedometer.watchStepCount is not working on Android
See original GitHub issueSummary
Pedometer.watchStepCount is not working on Android 11, tested on Samsung A71 and A51. Pedometer.isAvailableAsync() is returning true But the callback of Pedometer.watchStepCount never triggers, no matter how many steps I walked. It worked well in iOS.
Managed or bare workflow? If you have ios/
or android/
directories in your project, the answer is bare!
managed
What platform(s) does this occur on?
Android
SDK Version (managed workflow only)
41
Environment
Expo CLI 4.5.2 environment info: System: OS: macOS 11.4 Shell: 5.8 - /bin/zsh Binaries: Node: 14.17.0 - /usr/local/opt/node@14/bin/node Yarn: 1.22.10 - /usr/local/bin/yarn npm: 6.14.13 - /usr/local/opt/node@14/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman Managers: CocoaPods: 1.10.1 - /usr/local/bin/pod SDKs: Android SDK: API Levels: 16, 21, 23, 28, 29, 30 Build Tools: 28.0.3, 29.0.2, 30.0.3 System Images: android-29 | Intel x86 Atom_64, android-29 | Google APIs Intel x86 Atom, android-30 | Google APIs Intel x86 Atom, android-30 | Google Play Intel x86 Atom IDEs: Android Studio: 4.2 AI-202.7660.26.42.7351085 Xcode: /undefined - /usr/bin/xcodebuild npmPackages: expo: ~41.0.1 => 41.0.1 react: 16.13.1 => 16.13.1 react-dom: 16.13.1 => 16.13.1 react-native: https://github.com/expo/react-native/archive/sdk-41.0.0.tar.gz => 0.63.2 react-native-web: ~0.13.12 => 0.13.18 npmGlobalPackages: expo-cli: 4.5.2 Expo Workflow: managed
Reproducible demo or steps to reproduce from a blank project
You can test with the pedometer demo on the https://docs.expo.io/versions/latest/sdk/pedometer/ Or you can use my code
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { Pedometer } from 'expo-sensors';
export default class App extends React.Component {
state = {
isPedometerAvailable: 'checking',
pastStepCount: 0,
currentStepCount: 0,
};
componentDidMount() {
this._subscribe();
}
componentWillUnmount() {
this._unsubscribe();
}
_subscribe = () => {
this._subscription = Pedometer.watchStepCount(result => {
this.setState({
currentStepCount: result.steps,
});
});
Pedometer.isAvailableAsync().then(
result => {
this.setState({
isPedometerAvailable: String(result),
});
},
error => {
this.setState({
isPedometerAvailable: 'Could not get isPedometerAvailable: ' + error,
});
}
);
const end = new Date();
const start = new Date();
start.setDate(end.getDate() - 1);
Pedometer.getStepCountAsync(start, end).then(
result => {
this.setState({ pastStepCount: result.steps });
},
error => {
this.setState({
pastStepCount: 'Could not get stepCount: ' + error,
});
}
);
};
_unsubscribe = () => {
this._subscription && this._subscription.remove();
this._subscription = null;
};
render() {
return (
<View style={styles.container}>
<Text>Pedometer.isAvailableAsync(): {this.state.isPedometerAvailable}</Text>
<Text>Steps taken in the last 24 hours: {this.state.pastStepCount}</Text>
<Text>Walk! And watch this go up: {this.state.currentStepCount}</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
marginTop: 15,
alignItems: 'center',
justifyContent: 'center',
},
});
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (2 by maintainers)
Top GitHub Comments
I confirmed that this is a permission issue, we need a fitness permission in order to use the fitness data. I solve this by using a react native module https://github.com/zoontek/react-native-permissions. This is the best permission requesting module as it includes the latest permission. Even the official rn permission module from react native doesn’t include activity permission. expo please update the permission module
Same on Google Pixel 5 with Android 11 and latest sdk 42 (with either my own code or with the snack from the official doc). This is probably a Permission issue as Expo App have not the permission to access my fitness data. Calling getPermissionsAsync or requestPermissionAsync returns Authorized but does not request for permission at all.