Pedometer not working on Android

🐛 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).

1 possible answer(s) on “Pedometer not working on Android

  1. Yes you’re right – According to #4047 (comment), 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.