I am migrating a Android app to Jetpack Compose. Following this connectivity USB tutorial I requested USB permissions on the usb device that I am trying to connect.
Now with Jetpack Compose I think accompanist is the recommended approach to handle permissions.
https://google.github.io/accompanist/permissions/
@OptIn(ExperimentalPermissionsApi::class)
@Composable
private fun FeatureThatRequiresCameraPermission() {
// Camera permission state
val cameraPermissionState = rememberPermissionState(
android.Manifest.permission.CAMERA
)
if (cameraPermissionState.status.isGranted) {
Text("Camera permission Granted")
} else {
Column {
val textToShow = if (cameraPermissionState.status.shouldShowRationale) {
// If the user has denied the permission but the rationale can be shown,
// then gently explain why the app requires this permission
"The camera is important for this app. Please grant the permission."
} else {
// If it's the first time the user lands on this feature, or the user
// doesn't want to be asked again for this permission, explain that the
// permission is required
"Camera permission required for this feature to be available. " +
"Please grant the permission"
}
Text(textToShow)
Button(onClick = { cameraPermissionState.launchPermissionRequest() }) {
Text("Request permission")
}
}
}
}
How should I request permissions for this use case?
val usbManager = getSystemService(Context.USB_SERVICE) as UsbManager
usbManager.requestPermission(device, permissionIntent)