You are reading the docs for Health13.x, an older version. Go to 14.x, the latest version.
Workouts
Write exercise sessions with an activity type, energy burned and distance using writeWorkoutData.
Copy MarkdownOpen inOpen in GitHubView as MarkdownOpen in Scira AIOpen in ChatGPTOpen in ClaudeOpen in Cursor
writeWorkoutData writes an exercise session with its activity type, time range and optional energy and distance totals. To read workouts back, see Workout values.
Workout end time. On iOS, an end before start crashes the app. On Android, it must be after start, or writeWorkoutData returns false.
totalEnergyBurned
int?
No
—
Calories burned
totalEnergyBurnedUnit
HealthDataUnit
No
HealthDataUnit.KILOCALORIE
Energy unit. iOS only: Android always uses kilocalories.
totalDistance
int?
No
—
Distance covered
totalDistanceUnit
HealthDataUnit
No
HealthDataUnit.METER
Distance unit. iOS only: Android always uses meters.
title
String?
No
—
Workout title (Android only). Without it, the title is the activity type name, such as RUNNING.
recordingMethod
RecordingMethod
No
RecordingMethod.automatic
How the workout was recorded. iOS does not store it and throws an ArgumentError for a value other than manual or automatic. On Android, manual is stored as actively recorded and active as manual entry.
Some common values work on one platform only: TRADITIONAL_STRENGTH_TRAINING, FUNCTIONAL_STRENGTH_TRAINING and SOCCER on iOS, and STRENGTH_TRAINING, DANCING and SKIING on Android.
Many more are available. For the full list, see the HealthWorkoutActivityType enum in the API reference.
Warning
Activity types are platform-specific. The plugin validates the activity type and throws a HealthException if it is not supported on the current platform. On Android, ARCHERY, BIKING_STATIONARY, CURLING, HOCKEY, SOCCER and WALKING_TREADMILL pass this check, but writeWorkoutData returns false for them.
Activity types are mapped to Health Connect exercise types.
Some iOS-specific types may not have an exact Android equivalent.
Each total you pass is written as a separate distance or total calories record, which needs WRITE permission for DISTANCE_DELTA or TOTAL_CALORIES_BURNED. Without it, nothing is written and writeWorkoutData returns false.
Other apps may not display all workout details.
Android-only values, such as DANCING, SKIING and STRENGTH_TRAINING, throw a HealthException.
Workouts appear in the Apple Fitness app.
totalEnergyBurned is stored as the workout's active energy, which leaves out resting energy.
The plugin saves the workout without associated samples, such as heart rate.
Both platforms can attach a route to a workout. To get the workout UUID that finishWorkoutRoute needs, write the workout with writeWorkoutDataUUID instead. For the route methods, see startWorkoutRoute, insertWorkoutRouteData and finishWorkoutRoute in the API reference.