0
  1. I have already synced my application with Health Connect.
  2. Google Fit is synced with Health Connect (I can retrieve step count data correctly).
  3. If I manually unsync Google Fit from Health Connect, the retrieved step count is always 0.

I would like to determine the sync status between Google Fit and Health Connect. If they are not synced, I want to display a notification, similar to the Google Fit app (please see the screenshot).

thank

Sync fit with Health Connect screenshot

1
  • Please provide enough code so others can better understand or reproduce the problem. Commented Jul 30, 2024 at 0:51

1 Answer 1

0

The image you linked is specific to whether or not the user has Health Connect installed. This is a function provided by the Health Connect API. To determine this, you can use getSdkStatus:

val availabilityStatus = HealthConnectClient.getSdkStatus(context, providerPackageName)
if (availabilityStatus == HealthConnectClient.SDK_UNAVAILABLE) {
  return // early return as there is no viable integration
}
if (availabilityStatus == HealthConnectClient.SDK_UNAVAILABLE_PROVIDER_UPDATE_REQUIRED) {
  // Optionally redirect to package installer to find a provider, for example:
  val uriString = "market://details?id=$providerPackageName&url=healthconnect%3A%2F%2Fonboarding"
  context.startActivity(
    Intent(Intent.ACTION_VIEW).apply {
      setPackage("com.android.vending")
      data = Uri.parse(uriString)
      putExtra("overlay", true)
      putExtra("callerId", context.packageName)
    }
  )
  return
}
val healthConnectClient = HealthConnectClient.getOrCreate(context)
// Issue operations with healthConnectClient

This will tell you if the user has Health Connect installed.

If you specifically want to understand if the user has Google Fit synced with Health Connect, you should be able to check the DataOrigin in your ReadRecordsRequest to determine the package that wrote the data. This will only work after Google Fit has written something to the Health Connect store.

It's important to note that there are many apps compatible with Health Connect that write steps, not just Google Fit. It might make more sense to read an aggregate step count from Health Connect.

Sign up to request clarification or add additional context in comments.

1 Comment

If Google Fit has been synchronized with Health Connect but the step count in Google Fit is 0 (because the user hasn't been active), using ReadRecordsRequest will not retrieve DataOrigin since there is no data. How can we address the situation where synchronization has occurred but there is no physical activity, to let users know that they simply have no step count data rather than thinking synchronization hasn't occurred?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.