Last active
January 4, 2024 18:21
-
-
Save tdcolvin/7aa3c7d31c0f2e840ac5527c07dff6eb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val ALL_BLE_PERMISSIONS = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { | |
arrayOf( | |
Manifest.permission.BLUETOOTH_CONNECT, | |
Manifest.permission.BLUETOOTH_SCAN | |
) | |
} | |
else { | |
arrayOf( | |
Manifest.permission.BLUETOOTH_ADMIN, | |
Manifest.permission.BLUETOOTH, | |
Manifest.permission.ACCESS_FINE_LOCATION | |
) | |
} | |
@Composable | |
fun GrantPermissionsButton(onPermissionGranted: () -> Unit) { | |
val launcher = rememberLauncherForActivityResult( | |
contract = ActivityResultContracts.RequestMultiplePermissions() | |
) { granted -> | |
if (granted.values.all { it }) { | |
// User has granted all permissions | |
onPermissionGranted() | |
} | |
else { | |
// TODO: handle potential rejection in the usual way | |
} | |
} | |
// User presses this button to request permissions | |
Button(onClick = { launcher.launch(ALL_BLE_PERMISSIONS) }) { | |
Text("Grant Permission") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment