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

Getting an empty Array in every parameter request #118

Open
asiflhr opened this issue Jul 18, 2024 · 6 comments
Open

Getting an empty Array in every parameter request #118

asiflhr opened this issue Jul 18, 2024 · 6 comments

Comments

@asiflhr
Copy link

asiflhr commented Jul 18, 2024

Describe the bug
Getting an empty Array in every parameter request.

Expected behavior
Hi all, I tried more than 12 parameters I needed in my app one by one but every time I'm getting an empty Array [] in response. I've attached my function calls. Am I missing something or there is some other error?

useEffect(() => {
    const initializeHealthConnect = async () => {
      if (Platform.OS !== 'android') {
        return
      }

      try {
        const isInitialized = await initialize()
        console.log('is initialized: ', isInitialized)
        if (!isInitialized) {
          throw new Error('Health Connect initialization failed')
        }

        const grantedPermissions = await requestPermission([
          { accessType: 'read', recordType: 'Height' },
        ])

        console.log('granted permissions: ', grantedPermissions)

        if (!grantedPermissions) {
          throw new Error('Permissions not granted')
        }

        setPermissionsGranted(true)
      } catch (err) {
        console.error(
          'Error during initialization or permission request: ',
          err,
        )
        setError(err.message)
        setLoading(false)
      }
    }

    initializeHealthConnect()
  }, [])

  useEffect(() => {
    const fetchHealthData = async () => {
      if (permissionsGranted) {
        try {
          const result = await readRecords('Height', {
            timeRangeFilter: {
              operator: 'between',
              startTime: '2023-01-09T12:00:00.405Z',
              endTime: '2024-07-15T23:53:15.405Z',
            },
          })

          console.log('Retrieved record: ', JSON.stringify({ result }, null, 2))
          setHealthData(result)
        } catch (err) {
          console.error('Error fetching health data: ', err)
          setError(err.message)
        } finally {
          setLoading(false)
        }
      }
    }

    fetchHealthData()
  }, [permissionsGranted])

Environment:

  • Health Connect Version: 2.1.0
  • React Native Version: 0.74.3
  • New architecture enabled: No
  • Using Expo: Prebuild(Dev Client)
@matinzd
Copy link
Owner

matinzd commented Jul 19, 2024

Hey!

Have you added any entries to the health connect app or from any other source to the health connect? What do you expect to see?

@asiflhr
Copy link
Author

asiflhr commented Jul 22, 2024

Hey @matinzd ,

Thanks for reply. Actually, I don't know how to add any entries through health connect app of from other sources. I just installed Health Connect app from playstore and allowed permissions to related entry I want to fetch data about, and getting an empty array.

@matinzd
Copy link
Owner

matinzd commented Jul 22, 2024

Other apps or your app should put data in the health connect so that you can retrieve it. Without that, you'll get an empty array.

@asiflhr
Copy link
Author

asiflhr commented Jul 23, 2024

Hi @matinzd , Thanks for reply, If I want to track the Steps, do you have example for that how can we put data to the health connect.

@matinzd
Copy link
Owner

matinzd commented Jul 23, 2024

I saw a youtube video from Vadim while ago on youtube.

Here is the link: https://www.youtube.com/live/VVoXcr18mdo?si=B6jqo4ZzXNUYLJzy

He used my lib for the integration.

@asiflhr
Copy link
Author

asiflhr commented Jul 23, 2024

Thanks @matinzd , let me check

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

2 participants