Skip to content

Import and display workouts

WorkoutImporter wraps the active provider and raises progress and completion events while importing normalized WorkoutData records.

using System.Collections.Generic;
using HealthBridge;
using HealthBridge.Data;
using HealthBridge.Helpers;
var importer = new WorkoutImporter(HealthBridgeService.Provider);
var options = ImportOptions.ForManualImport(
daysBack: 14,
maxWorkouts: 50);
List<WorkoutData> workouts = await importer.ImportWorkouts(options);

Guard this flow with HealthBridgeService.IsReady and a non-null provider.

Common fields include:

  • Id: provider record identifier.
  • ExerciseType: normalized activity label.
  • StartTime and EndTime: UTC Unix milliseconds; Duration: elapsed milliseconds.
  • Nullable calories, distance, and steps.
  • Location: indoor, outdoor, or unknown.
  • Source: contributing provider or app.
  • TimeInHrZones: seconds per shared zone when available.

Workout read distance is expressed in kilometers. Do not confuse it with the meter-based WorkoutWriteSample.DistanceMeters field.

Platforms and source devices do not populate every metric. Hide nullable fields when absent. Do not render an unavailable value as zero.

Unknown imported iOS activity values normalize to Other; keep those workouts visible.

Subscribe in OnEnable and unsubscribe in OnDisable:

  • HealthBridgeEvents.OnImportStarted
  • HealthBridgeEvents.OnWorkoutProcessed
  • HealthBridgeEvents.OnWorkoutsImported
  • HealthBridgeEvents.OnImportFailed

Use these events for progress UI, but keep the awaited import result as the authoritative data returned to the caller.

Use EditorWorkoutConfig to test complete workouts, missing optional metrics, indoor activities, Other, and an empty list.