Pedometer fails after building standalon app

I added the pedometer to the project, in development server it worked correctly, That means after npm start and launch on the phone through QR code Pedometer worked correctly.

but after signing to APK through exp build: android and start APK on phone the pedometer not worked.

app.js :

import React from "react";
import { StyleSheet, Text, View } from "react-native";
import GyroscopeSensor from './GyroscopeSensor';
import Gps from './Gps';
import PedometerSensor from './PedometerSensor';
import Expo from "expo";

export default class App extends React.Component {
  render() {
    return (
      <View style={styles.container}>
        <PedometerSensor />
        <Gps />
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    marginTop: 15,
    alignItems: "center",
    justifyContent: "center"
  }
});

PedometerSensor :

import Expo from "expo";
import React from "react";
import { Pedometer } from "expo";
import { StyleSheet, Text, View } from "react-native";

export default class PedometerSensor 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"
  }
});

app.json

{
  "expo": {
   "name": "test5",
   "icon": "./sepila.png",
   "version": "2.0.0",
   "slug": "your-app-slug",
   "sdkVersion": "21.0.0",
   "ios": {
     "bundleIdentifier": "com.milad5.test"
   },
   "android": {
     "package": "com.milad5.test"
   }
  }
}

Hey sorry about this issue. I think you need to configure a android oauth client for you app on the google play console for it to work on Android in standalone. See یک شناسه مشتری OAuth 2.0 دریافت کنید  |  Google Fit  |  Google Developers. Let me know if that works I will update the documentation to mention that.

1 Like

thanx for the answer . can you help me to Find app’s certificate information.
keystore and production-keystore
and
keytool -list -v -keystore your_keystore_name -alias your_alias_name

You should be able to get it using keytool -list -printcert -jarfile growler.apk | grep SHA1 | awk '{ print $2 }' Where growler.apk is the path you your app’s apk.

1 Like

I did this work. but now I need change app.json? Must I be added clientid in app.json?

pls, guide me how to add client id to my project. I added signInWithGoogleAsync() function to my component :


import React from 'react' ;
import Expo from "expo";
import { Pedometer } from "expo";
import { StyleSheet, Text, View } from 'react-native';
import { giveSteps,giveStepsPast } from '../actions'
import { connect } from 'react-redux';
import { ShowCircles } from '../components/ShowCircles'
import reducer from '../reducers';

async function signInWithGoogleAsync() {
  try {
    const result = await Expo.Google.logInAsync({
      androidClientId: "1111111111111111111111111111111111111111111111111111111",
      scopes: ['profile', 'email']
    });

    if (result.type === 'success') {
      return result.accessToken;
    } else {
      return {cancelled: true};
    }
  } catch(e) {
    return {error: true};
  }
}


class GetPedometer extends React.Component {
  state = {
    isPedometerAvailable : "checking"
  }
    componentDidMount() {
      this._subscribe();
      signInWithGoogleAsync();
    }
  
    componentWillUnmount() {
      this._unsubscribe();
      
    }
  
    _subscribe = () => {
      this._subscription = Pedometer.watchStepCount(result => {
        this.props.dispatch(giveSteps(result.steps)); 
        
      });
      
      Pedometer.isAvailableAsync().then(
        result => {
          this.setState({
            isPedometerAvailable: String(result)
          });
           return String(result);
          
         
        },
        error => {
          this.setState({
            isPedometerAvailable: "Could not get isPedometerAvailable: " + error
          });
         return 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 });
          this.props.dispatch(giveStepsPast(result.steps));
        },
        error => {
       //   this.setState({
        //    pastStepCount: "Could not get stepCount: " + error
        //  });
        }
      );
    };
  
    _unsubscribe = () => {
      this._subscription && this._subscription.remove();
      this._subscription = null;
    };
    render() {
      return(
        <View>
      <Text> {this.state.isPedometerAvailable}  </Text>
      <Text> pedometer </Text>
      </View>
      )
    }
  }

  GetPedometer = connect()(GetPedometer);
  
  export default GetPedometer;
  const styles = StyleSheet.create({
    container: {
      flex : 1,
      justifyContent: 'center'
    },
  });

but received this error on my android device.

There is actually nothing needed to be done in the app, you just need to create a client in the Google console for you app package + keystore hash.

1 Like

tnx, it worked. my problems solved.

please update pedometer document with this instruction.

Thanks for this, saved me. Really should be in the documentation I think

1 Like

Android Pedometer Standalone, I made a client id and everything but after the auth flow starts in the app, I choose an account to use and then the flow closes. Pedometer still won’t let me get step count. Ideas?

Solution was to use this particular SHA when setting up your client id. The keytool SHA was incorrect in my case.

i havent understood how to configure a goog OAuth client id for my pedometer app…please help me…
what do i need to give while its asking the path to keystore…

keytool -list -v -keystore your_keystore_name -alias your_alias_name

1 Like

I’ve been having this problem and I’ve tried using keytool -list -printcert -jarfile growler.apk | grep SHA1 | awk ‘{ print $2 }’ in the directory I downloaded my apk to, but it’s telling me grep is not recognized as a command. Any advice?

Having trouble with this.
I selected “Get a Client ID” from:

Selected an existing project that I was using for google authentication. “Fitness API has been enabled. Next, to use the API you’ll need the right credentials.”

Selected Fitness API and that I’d be accessing it from Android. Additionally I choose user data. When I go to select credentials it tells me I already have credentials fit for purpose.

I select Done but my pedometer component still gives values that haven’t been updated. Pedometer.isAvailableAsync() as written in the expo docs:

never has it’s state updated from checking. Am I missing something?

I have tried looking at this:

But when I try the command:

keytool -list -printcert -jarfile growler.apk | grep SHA1 | awk ‘{ print $2 }’

in the directory with my apk (currently downloads), it tells me grep isn’t a recognized command.

Thanks in advance for your help, I’m fretting this a bit!

hi @hmadugula !! have you solve this problem plz