Skip to content

Read health data

HealthBridge returns HealthDataReadResult with typed HealthDataSample subclasses where the public API supports them.

var query = new HealthDataQuery(
"steps",
daysBack: 7,
maxRecords: 100);
HealthDataReadResult result =
await HealthBridgeService.ReadDataAsync(query);
if (!result.Success)
{
// Show a recoverable error.
return;
}
foreach (HealthDataSample sample in result.Samples)
{
if (sample is StepsSample steps)
{
long count = steps.Count;
// Update a transient view model.
}
}

Queries clamp daysBack to 1–90 and maxRecords to at least one.

Prefer typed models such as:

  • StepsSample
  • SleepSample
  • WeightSample
  • CaloriesSample
  • DistanceSample
  • NutritionSample
  • HydrationSample

For another registry-backed type, use GetValue<T>(key) on the base sample. There is no universal Value property.

Before generating dynamic UI, use HealthDataTypeRegistry to inspect display name, category, platform support, public API status, permission mappings, and write support.

A registry row can exist for permission configuration without a typed public read/write model. Check public API status and provider capability.

  • Success=false: show a recoverable error state.
  • Successful empty result: show a normal empty state.
  • Missing generic value: keep it unavailable.
  • iOS empty result: do not infer permission or absence of records.