Nastya Kholodova
Nastya Kholodova

Reputation: 1321

Can I record workout data to GoogleFit from WearOS app?

I'm making a fitness wearOS app. I want to record workouts completed with the app to GoogleFit.

Is there a way to do that from WearOS?

I start a workout using HealthServices:

suspend fun startExercise() {
    val dataTypes = setOf(
        DataType.HEART_RATE_BPM,
        DataType.LOCATION

    )
    val aggregateDataTypes = setOf(
        DataType.DISTANCE,
        DataType.TOTAL_CALORIES
    )
    val config = ExerciseConfig.builder()
        .setExerciseType(ExerciseType.RUNNING)
        .setDataTypes(dataTypes)
        .setAggregateDataTypes(aggregateDataTypes)
        .setShouldEnableAutoPauseAndResume(false)
        .setShouldEnableGps(true)
        .build()
    HealthServices.getClient(this /*context*/)
        .exerciseClient
        .startExercise(config)
        .await()
}

(Code is from this example https://developer.android.com/training/wearables/health-services/active#start)

I was expecting if I would start/end a workout with HealthServices it would auto-magically sync the data to GoogleFit(Apple does this with for HealthKit).

So, can I record workout data to GoogleFit from a WearOS app?

Upvotes: 1

Views: 137

Answers (1)

Bardy
Bardy

Reputation: 2170

To add to the Yuri's comment that this isn't possible automatically, the SessionClient is probably what you'd want in order to do this manually. The flow would be:

  1. Collect data with Health Services
  2. Transform
  3. Insert session with SessionClient

The insert a session snippet in the Google Fit docs is a relevant example, as it both sets the session type (in this case, running) and then also adds the underlying data (instead of doing that separately with HistoryClient).

Update: You may also wish to take a look at Health Connect, which was recently announced.

Upvotes: 2

Related Questions