Как получить vo2_max и местоположение в Wear OS с помощью служб здравоохранения

Я использовал службу здравоохранения, чтобы получить vo2_max и местоположение, начав упражнение.

приостановить веселье startExercision (healthServicesClient: УпражнениеКлиент) { val dataTypes = setOf(HEART_RATE_BPM,CALORIES_TOTAL,DISTANCE,DISTANCE_TOTAL, SPEED, STEPS, STEPS_TOTAL, LOCATION, VO2_MAX, VO2_MAX_STATS)

          val config = ExerciseConfig(
        exerciseType = ExerciseType.RUNNING,
        dataTypes = dataTypes,
        isAutoPauseAndResumeEnabled = false,
        isGpsEnabled = true,
    )
    healthServicesClient.startExercise(config)
    lifecycleScope.launch {
        updateData(healthServicesClient)
    }
}

приостановить веселье updateData( healthServicesClient: PracticeClient) {

      val callback = object : ExerciseUpdateCallback {
    override fun onExerciseUpdateReceived(update: ExerciseUpdate) {
        val exerciseStateInfo = update.exerciseStateInfo
        val activeDuration = update.activeDurationCheckpoint
        val latestMetrics = update.latestMetrics
        val latestGoals = update.latestAchievedGoals

        runOnUiThread{
            if(latestMetrics.getData(VO2_MAX_STATS)!= null){
                binding.vo2max.text= "vo2max= ${latestMetrics.getData(VO2_MAX_STATS)!!.max.toString()}"
            }
            if(latestMetrics.getData(LOCATION).isNotEmpty()){
                binding.location.text= "calories= ${latestMetrics.getData(LOCATION)!!.last().value.latitude}"
            }
            if(latestMetrics.getData(HEART_RATE_BPM).isNotEmpty()){
                binding.textt.text= "heart rate= ${latestMetrics.getData(HEART_RATE_BPM).last().value.toString()}"
            }
            if(latestMetrics.getData(STEPS_TOTAL)!=null){
                binding.stepCount.text= "stepCount= ${latestMetrics.getData(STEPS_TOTAL)!!.total.toString()}"
            }
            if(latestMetrics.getData(DISTANCE_TOTAL)!= null){
                binding.distance.text= "distance= ${latestMetrics.getData(DISTANCE_TOTAL)!!.total.toString()}"
            }
            if(latestMetrics.getData(SPEED).isNotEmpty()){
                binding.speed.text= "speed= ${latestMetrics.getData(SPEED).last().value}"

            }
        }


    }

    override fun onLapSummaryReceived(lapSummary: ExerciseLapSummary) {
        // For ExerciseTypes that support laps, this is called when a lap is marked.
    }

    override fun onRegistered() {

    }

    override fun onRegistrationFailed(throwable: Throwable) {

    }

    override fun onAvailabilityChanged(
        dataType: androidx.health.services.client.data.DataType<*,*>,
        availability: Availability
    ) {
        // Called when the availability of a particular DataType changes.
        when {
            availability is LocationAvailability -> {
                Log.d("getLocationAvailability", availability.name.toString())
                Log.d("getLocationAvailability", availability.toString())
            }
                availability is DataTypeAvailability -> {

                }
        }
    }

}
healthServicesClient.setUpdateCallback(callback)

}

0 ответов

Другие вопросы по тегам