Differential changes API

Stay organized with collections Save and categorize content based on your preferences.

This API enables developers to retrieve changes made to Health Connect by deploying a changes token.

Integrating with the differential changes API

Use the following example to integrate the Differential Changes API in Health Connect. Changes are retrieved from Health Connect only when your app requests them.

  1. First, obtain an initial changes token. This changes token represents the point in commit history from which changes will be taken.
val changesToken =
  client.getChangesToken(
    ChangesTokenRequest(
      recordTypes = setOf(StepsRecord::class),
    )
  )

Note that the changes token is only valid for 30 days. Ensure the following:

  1. Your app is updating from changes much more regularly than this to avoid stale tokens.
  2. Your app can handle the case where the token is no longer valid, and has a fallback mechanism for obtaining the necessary data.
  3. Request changes after obtaining the changes token:
val response = client.getChanges(changesToken)
for (change in response.changes) {
  // Process each change
}