ExerciseRouteRequestContract


class ExerciseRouteRequestContract : ActivityResultContract


An ActivityResultContract to request a route associated with an androidx.health.connect.client.records.ExerciseSessionRecord.

It receives the session id as input and returns an ExerciseRoute as output, if available.

import androidx.health.connect.client.contracts.ExerciseRouteRequestContract
import androidx.health.connect.client.readRecord
import androidx.health.connect.client.records.ExerciseRoute
import androidx.health.connect.client.records.ExerciseRouteResult
import androidx.health.connect.client.records.ExerciseSessionRecord

// See https://developer.android.com/training/basics/intents/result#launch for appropriately
// handling ActivityResultContract.
val requestExerciseRoute =
    activityResultCaller.registerForActivityResult(ExerciseRouteRequestContract()) {
        exerciseRoute: ExerciseRoute? ->
        if (exerciseRoute != null) {
            displayExerciseRoute(exerciseRoute)
        } else {
            // Consent was denied
        }
    }

// Show exercise route, based on user action
val exerciseSessionRecord =
    healthConnectClient.readRecord<ExerciseSessionRecord>(recordId).record

when (val exerciseRouteResult = exerciseSessionRecord.exerciseRouteResult) {
    is ExerciseRouteResult.Data -> displayExerciseRoute(exerciseRouteResult.exerciseRoute)
    is ExerciseRouteResult.ConsentRequired -> requestExerciseRoute.launch(recordId)
    is ExerciseRouteResult.NoData -> Unit // No exercise route to show
    else -> Unit
}

Summary

Public constructors

Public functions

open Intent
createIntent(context: Context, input: String)

Creates an intent to request an ExerciseRoute.

open ExerciseRoute?
parseResult(resultCode: Int, intent: Intent?)

Converts the activity result into ExerciseRoute, to return as output.

Inherited functions

From androidx.activity.result.contract.ActivityResultContract
open ActivityResultContract.SynchronousResult<ExerciseRoute?>?
getSynchronousResult(context: Context, input: String)

An optional method you can implement that can be used to potentially provide a result in lieu of starting an activity.

Public constructors

ExerciseRouteRequestContract

Added in 1.1.0-alpha10
ExerciseRouteRequestContract()

Public functions

createIntent

Added in 1.1.0-alpha10
open fun createIntent(context: Context, input: String): Intent

Creates an intent to request an ExerciseRoute. It receives the exercise session id as input.

Parameters
context: Context

the context

input: String

the exercise session id obtained via androidx.health.connect.client.records.ExerciseSessionRecord.metadata

Throws
kotlin.IllegalArgumentException

if the input is an empty string.

See also
createIntent

parseResult

Added in 1.1.0-alpha10
open fun parseResult(resultCode: Int, intent: Intent?): ExerciseRoute?

Converts the activity result into ExerciseRoute, to return as output.

Returns
ExerciseRoute?

null if the user didn't grant access to the exercise route or if there's no exercise route for the session id passed on createIntent.

See also
parseResult