matinzd/react-native-health-connect

Power returns empty array

Closed this issue · 4 comments

Describe the bug
I've logged an exercise via Google Fit (manually) which includes Power. But the request to readRecords for Power returns an empty array. ExerciseSession comes normally... No errors on logcat, power permission enabled on Health Connect.

To Reproduce
Steps to reproduce the behavior:

  1. Log a exercise via Google Fit (set a Power value)
  2. Go to Health Connect
  3. Click on Data and access > Activity > Power > See all entries
  4. The Power entry is there (on Health Connect)
  5. Code below returns empty array

Expected behavior
Should return an array of Power.

Minimal Reproducible

export const readAndroidSampleData = async () => {
  const isInitialized = await initialize();
  const grantedPermissions = await requestPermission([
    { accessType: "read", recordType: "ExerciseSession" },
    { accessType: "read", recordType: "Power" },
  ]);

  console.log("granted permissions:", grantedPermissions); // permission granted

  const exerciseRecords = await readRecords("ExerciseSession", {
    timeRangeFilter: {
      operator: "between",
      startTime: "2024-07-09T12:00:00.405Z",
      endTime: "2024-08-20T23:53:15.405Z",
    },
  });

  for (const exerciseRecord of exerciseRecords) {
    console.log("exerciseRecord:", exerciseRecord);

    const exercisePower = await readRecords("Power", {
      timeRangeFilter: {
        operator: "between",
        startTime: exerciseRecord.startTime,
        endTime: exerciseRecord.endTime,
      },
    });
    console.log("exercisePower:", exercisePower); // empty array

    console.log("=====================================");
  }
};

Environment:

  • Health Connect Version: 2024.07.11.00.release
  • React Native Version: 0.74.3
  • New architecture enabled: No
  • Using Expo: Prebuild(Dev Client)

Power and ExerciseSession are separate entities in health connect. Google Fit needs to write the Power data in health connect in order for you to be able to read it.

Try manually adding some Power records and see if you still get empty array.

I manually added some power data and it's being returned when I want it.

Screenshot 2024-08-01 at 14 15 58

Ah, I think I found the problem on my side. When I fetch the ExerciseRecord, it returns to me the endDate with 1ms less than the PowerRecord endDate:

ExerciseRecord:

{
  "title": "Test Google Fit"
  "exerciseRoute": {},
  "exerciseType": 8,
  "laps": [],
  "metadata": {...},
  "notes": null,
  "segments": [],
  "endTime": "2024-08-01T00:50:00.237Z",   <-----
  "startTime": "2024-08-01T00:20:00.237Z"
}

PowerRecord:

{
  "metadata": {...},
  "samples": [...],
  "endTime": "2024-08-01T00:50:00.238Z",   <-----
  "startTime": "2024-08-01T00:50:00.237Z"
}

I think you can close the issue.

Oh wow! :) Good to know.