Pedometer not working on Android
See original GitHub issue🐛 Bug Report
Summary of Issue
Pedometer is not working on android (I’ve literally copied the code from the docs) and says “step count for date range is not supported on Android yet”
Environment - output of expo diagnostics
& the platform(s) you’re targeting
Expo CLI 3.22.3 environment info: System: OS: Windows 10 10.0.18363 Binaries: Node: 12.18.2 npm: 6.14.5 IDEs: Android Studio: Version 4.0.0.0 AI-193.6911.18.40.6514223 npmPackages: expo: ^38.0.0 => 38.0.8 react: 16.11.0 => 16.11.0 react-dom: 16.11.0 => 16.11.0 react-native: https://github.com/expo/react-native/archive/sdk-38.0.2.tar.gz => 0.62.2 react-native-web: ~0.11.7 => 0.11.7 react-navigation: ^4.3.9 => 4.4.0
Reproducible Demo
import React from 'react';
import { Pedometer } from 'expo-sensors';
import { StyleSheet, Text, View } from 'react-native';
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',
},
});
Steps to Reproduce
Simply run the app and show this view.
Expected Behavior vs Actual Behavior
I’m expecting to get step count, but I’m getting an error (previously mentioned on summary of issue).
Issue Analytics
- State:
- Created 3 years ago
- Comments:14 (6 by maintainers)
Top Results From Across the Web
My pedometer isn't working properly (Android only)
My pedometer isn't working properly (Android only) · 1. Go to mobile Settings → Battery & Performance → find "Battery Saver" → choose...
Read more >Google Fit Not Counting Steps on Your Android Phone? 5 ...
1. Reset Activity Tracker Settings · Open the Google Fit app and tap the profile icon. · Tap on Settings (the gear icon)...
Read more >Support - Android - StepsApp Pedometer
Troubleshooting · How do I grant access for Physical Activity? How do I force quit and restart?
Read more >Pacer Android stopped counting my steps. What should I do?
The Android operating system can prevent Pacer from running in the background, which will result in lost steps/distance.
Read more >pedometer not working... - Android Forums at AndroidCentral ...
Mine also stopped working after an update. I went into running apps and 'force stopped' two S Health applications and then restated my...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
There are no plans to implement this for Android (unless something changes and Android e.g. 13 starts supporting it natively through OS). The implementation from ancient SDK 33 used Google Fit, but we don’t want this included in Expo Go anymore. As being said above, GoogleFit is not supported by all Android phones, so it’s not worth the extra size if it’s not going to work on all devices.
A better news is that now, instead of Expo Go, you can build your own development client and customize its native code to support GoogleFit / Samsung Fit / whatever. This is not as convenient as having it directly in Expo Go, but this is the official and recommended way when you need any native APIs that are not included in Expo Go.
In the future, a community-driven package might appear like
expo-fitness
, but it’s a matter of year or so and I’m just speculating (just gossip). If somehow it really happens, I’ll let you know 😄Yes you’re right - According to https://github.com/expo/expo/pull/4047#discussion_r277892367, before migrating to unimodules, it used to get data from Google Fitness API, now it uses Android hardware sensors API. We’re going to discuss restoring Fit API internally. However, you can still use Fitness REST API in conjunction with Expo AuthSession to get the data you need.