ExerciseRouteRequestContract


public final class ExerciseRouteRequestContract extends 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 methods

@NonNull Intent

Creates an intent to request an ExerciseRoute.

ExerciseRoute
parseResult(int resultCode, Intent intent)

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

Inherited methods

From androidx.activity.result.contract.ActivityResultContract
ActivityResultContract.SynchronousResult<ExerciseRoute>

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
public ExerciseRouteRequestContract()

Public methods

createIntent

Added in 1.1.0-alpha10
public @NonNull Intent createIntent(@NonNull Context context, @NonNull String input)

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

Parameters
@NonNull Context context

the context

@NonNull String input

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
public ExerciseRoute parseResult(int resultCode, Intent intent)

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