Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

We need to open the Google fit app to receive the updated steps #146

Open
IlanAMG opened this issue Sep 2, 2024 · 2 comments
Open

We need to open the Google fit app to receive the updated steps #146

IlanAMG opened this issue Sep 2, 2024 · 2 comments

Comments

@IlanAMG
Copy link

IlanAMG commented Sep 2, 2024

We want to retrieve the steps of the day and display them on our application.
With the Google Fit API which will be deprecated, we were able to do this.
Since we moved to Health Connect, the steps only update when we open the Google Fit app and return to our app.

Note that with another pedometer connected to Health connect, such as Samsung Health for example, the steps are updated in real time without needing to open Samsung Health, I suppose the problem is only linked to Google Fit.

Are you aware of this problem and do you have any suggestions?

Thanks.

Code :

export const useGetCurrentStepsAndroid = () => {
  //...
 

  const onStepsObserver = useCallback(async () => {
    if (!isAvailable || !authorized) {
      return
    }

    try {
      const startDate = startOfDay(new Date())
      const now = new Date()

      const options = {
        operator: 'between',
        startTime: startDate.toISOString(),
        endTime: now.toISOString(),
      }

      const results = await readRecords('Steps', {
        timeRangeFilter: options,
      })

      if (!results || results?.records?.length === 0) {
        dispatch(setSteps(0))
        return
      }

      dispatch(
        setSteps(
          Math.round(
            Math.max(
              ...Object.values(
                results.records.reduce((acc, item) => {
                  const origin = item.metadata.dataOrigin
                  if (!acc[origin]) {
                    acc[origin] = 0
                  }
                  acc[origin] += item.count
                  return acc
                }, {}),
              ),
            ),
          ),
        ),
      )
    } catch (error) {
      handleError(error)
      dispatch(setSteps(0))
    }
  }, [authorized, dispatch, isAvailable])

  useInterval(() => {
    onStepsObserver()
  }, 3000)

  //...

  return {
    steps,
  }
}

Environment:

  • Health Connect Version: 3.1.0
  • React Native Version: 0.72.4
  • New architecture enabled: No
  • Using Expo: No
  • Android API Level: API 34 (Android 14)
@GSSPawanKumarSingh
Copy link

Have any one find any solution for this?

@Diogo107
Copy link

This seems to be an issue also for me.
I'm developing something that needs to get the device steps but forcing the user to install Google Fit and Health Connect is a very poor User Experience... hopefully some solution will come up...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants