Skip to content

Commit cab6915

Browse files
committed
add heart rate permissions
1 parent 589b1d7 commit cab6915

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

sft/src/main/AndroidManifest.xml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,12 @@
1919
<uses-permission android:name="android.permission.WAKE_LOCK" />
2020
<uses-feature android:name="android.hardware.type.watch" />
2121
<uses-permission android:name="android.permission.BODY_SENSORS"
22-
android:maxSdkVersion="36" />
22+
android:maxSdkVersion="35" />
2323
<uses-permission android:name="android.permission.BODY_SENSORS_BACKGROUND"/>
2424
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />
2525
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
2626
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
2727
<uses-permission android:name="android.permission.health.READ_HEART_RATE" />
28-
<uses-permission android:name="android.permission.health.READ_HEALTH_DATA_IN_BACKGROUND" />
29-
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
3028

3129

3230
<application

sft/src/main/java/com/example/sft/presentation/MainActivity.kt

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,19 @@ package com.example.sft.presentation
1818

1919
import android.Manifest
2020
import android.app.Activity
21+
import android.health.connect.HealthPermissions
22+
import android.os.Build
2123
import android.os.Bundle
2224
import androidx.activity.ComponentActivity
2325
import androidx.activity.compose.setContent
26+
import androidx.activity.compose.rememberLauncherForActivityResult
27+
import androidx.activity.result.contract.ActivityResultContracts
2428
import androidx.compose.foundation.layout.Box
2529
import androidx.compose.foundation.layout.fillMaxSize
2630
import androidx.compose.foundation.layout.fillMaxWidth
2731
import androidx.compose.runtime.Composable
2832
import androidx.compose.runtime.LaunchedEffect
33+
import androidx.compose.runtime.collectAsState
2934
import androidx.compose.runtime.getValue
3035
import androidx.compose.runtime.mutableStateOf
3136
import androidx.compose.runtime.remember
@@ -35,27 +40,24 @@ import androidx.compose.ui.Modifier
3540
import androidx.compose.ui.platform.LocalContext
3641
import androidx.compose.ui.res.stringResource
3742
import androidx.compose.ui.text.style.TextAlign
43+
import androidx.lifecycle.viewmodel.compose.viewModel
3844
import androidx.wear.compose.foundation.lazy.TransformingLazyColumn
3945
import androidx.wear.compose.foundation.lazy.items
4046
import androidx.wear.compose.foundation.lazy.rememberTransformingLazyColumnState
41-
import androidx.wear.compose.material3.Text
4247
import androidx.wear.compose.material3.AppScaffold
4348
import androidx.wear.compose.material3.Button
4449
import androidx.wear.compose.material3.ButtonDefaults
4550
import androidx.wear.compose.material3.ListHeader
4651
import androidx.wear.compose.material3.MaterialTheme
4752
import androidx.wear.compose.material3.ScreenScaffold
53+
import androidx.wear.compose.material3.Text
4854
import androidx.wear.compose.navigation.SwipeDismissableNavHost
4955
import androidx.wear.compose.navigation.composable
5056
import androidx.wear.compose.navigation.rememberSwipeDismissableNavController
5157
import com.example.sft.R
5258
import com.example.sft.presentation.theme.WearAppTheme
5359
import com.google.android.horologist.compose.layout.ColumnItemType
5460
import com.google.android.horologist.compose.layout.rememberResponsiveColumnPadding
55-
import androidx.activity.compose.rememberLauncherForActivityResult
56-
import androidx.activity.result.contract.ActivityResultContracts
57-
import androidx.compose.runtime.collectAsState
58-
import androidx.lifecycle.viewmodel.compose.viewModel
5961

6062
class MainActivity : ComponentActivity() {
6163

@@ -112,12 +114,17 @@ fun ExerciseSelectionScreen(
112114

113115
LaunchedEffect(Unit) {
114116
exercises = exerciseRepository.exercises
115-
val permissions = arrayOf(
117+
val permissions = mutableListOf(
116118
Manifest.permission.BODY_SENSORS,
117119
Manifest.permission.ACTIVITY_RECOGNITION,
118120
Manifest.permission.ACCESS_COARSE_LOCATION,
119-
Manifest.permission.ACCESS_FINE_LOCATION
120-
)
121+
Manifest.permission.ACCESS_FINE_LOCATION,
122+
).apply {
123+
//Granular heart rate permission for Wear 6+
124+
if (Build.VERSION.SDK_INT >= 36) {
125+
this.add(HealthPermissions.READ_HEART_RATE)
126+
}
127+
}.toTypedArray()
121128
permissionLauncher.launch(permissions)
122129
}
123130

@@ -144,7 +151,7 @@ fun ExerciseSelectionScreen(
144151
modifier = Modifier.fillMaxSize()
145152
) {
146153
item {
147-
ListHeader() { Text(text = "Workouts") }
154+
ListHeader { Text(text = "Workouts") }
148155
}
149156
items(exercises) { exercise ->
150157
Button(

0 commit comments

Comments
 (0)