2

I'd like to know what's the best way to fetch pedometer data from the phone (especially Android). Firstly I thought I could run a task in the background and subscribe to the step sensor via react-native-universal-pedometer npm package but I found out that this is not possible in RN. Then I tried react-native-google-fit package where you can query steps data from date to date but the module is quite buggy. Is there a better way of fetching pedometer data as well as average walking velocity while maintaining battery efficiency?

2 Answers2

4

You can use these methods:

1- Google fit API: https://www.npmjs.com/package/react-native-google-fit

2- Expo Pedometer: https://docs.expo.io/versions/latest/sdk/pedometer/

3- Create your own Pedometer Native Module by using sensors: https://react-native-sensors.github.io/docs/Usage.html

gypsicoder
  • 5,416
  • 5
  • 24
  • 38
Ali Hesari
  • 1,821
  • 5
  • 25
  • 51
1

Best way to fetch data is :-

  1. Log in to your application using Firebase.
  2. Firebase will return 3 tokens i.e idToken, accessToken, refreshToken
  3. Now use the aggregate service of googleFit which you can find in the Google console.
  4. Hit a POST request to the aggregate service by passing the accessToken in the header section.
  5. Fetch the result and use the same anywhere in your application.

This is the best method that I have found so far. This is valid for both react and for react-native. In addition, it does not matter if you are using the android or the iOS

vaibhav gera
  • 101
  • 2
  • No Pedometer is required for this. No changes are to be done in of the Project files that exist in the react-native or android project – vaibhav gera Jan 14 '20 at 07:25