matinzd / react-native-health-connect

React native library for health connect (Android only)
http://matinzd.github.io/react-native-health-connect
MIT License
224 stars 43 forks source link

FloorsClimbed #75

Closed kfchan-git closed 6 months ago

kfchan-git commented 7 months ago

Describe the bug just wanna ask if the FloorsClimbed requires the sports app (e.g. Google Fit) to have floors/flights api included itself in order to retrieve data? cuz i'm getting an empty [] after calling

export const readFloorsClimbed = (startDate: string, endDate: string) => {
  return new Promise((resolve, reject) => {
    readRecords('FloorsClimbed', {
      timeRangeFilter: {
        operator: 'between',
        startTime: startDate,
        endTime: endDate,
      },
    })
      .then((res: any) => {

        resolve(res);
      })
      .catch((err: any) => {
        reject(err);
      });
  });
};

with the following permssion enabled

requestPermission([
            {accessType: 'read', recordType: 'Steps'},
            {accessType: 'read', recordType: 'SleepSession'},
            {accessType: 'read', recordType: 'Distance'},
            {accessType: 'read', recordType: 'FloorsClimbed'},
            {accessType: 'read', recordType: 'ActiveCaloriesBurned'},
            { accessType: 'read', recordType: 'TotalCaloriesBurned' },
            {accessType: 'read', recordType: 'HeartRate'},
          ])
            .then((res: any) => {
              console.log(`request permission ${JSON.stringify(res)}`);
              /* Called after we receive a response from the system */
              if (res?.length > 0) {
                resolve(res);
              } else {
                reject(res);
              }
            })
            .catch((err: any) => {
              console.log(`app error ${JSON.stringify(err)}`);
              reject(err);
            });

and the android manifest included:

<uses-permission android:name="android.permission.health.READ_STEPS"/>
   <uses-permission android:name="android.permission.health.READ_DISTANCE"/>
   <uses-permission android:name="android.permission.health.READ_SLEEP"/>
   <uses-permission android:name="android.permission.health.READ_FLOORS_CLIMBED"/>
   <uses-permission android:name="android.permission.health.READ_ACTIVE_CALORIES_BURNED"/>
   <uses-permission android:name="android.permission.health.READ_TOTAL_CALORIES_BURNED"/>
   <uses-permission android:name="android.permission.health.READ_HEART_RATE"/>

Environment:

KesoGizmoYoshi commented 7 months ago

Yes, you need a fitness app that writes data to Health Connect.

kfchan-git commented 7 months ago

seems like not all apps will count the flights of stairs, some would only just convert it as energy e.g. Samsung Health

matinzd commented 6 months ago

Yes, some other apps needs to write data to health connect. Health Connect itself doesn't provide any data. It acts like a hub where every app can write/read from/to it. Hope that solves your issue!