Skip to content

Commit

Permalink
Merge pull request #1383 from google/mv/permissions-docs-update
Browse files Browse the repository at this point in the history
Fix Permissions docs
  • Loading branch information
bentrengrove committed Nov 2, 2022
2 parents 76b7d9b + 941f744 commit 916e1bb
Showing 1 changed file with 26 additions and 22 deletions.
48 changes: 26 additions & 22 deletions docs/permissions.md
Expand Up @@ -28,6 +28,7 @@ Both APIs expose properties for you to follow the workflow as described in the
The following code exercises the [permission request workflow](https://developer.android.com/training/permissions/requesting#workflow_for_requesting_permissions).

```kotlin
@OptIn(ExperimentalPermissionsApi::class)
@Composable
private fun FeatureThatRequiresCameraPermission() {

Expand All @@ -36,28 +37,24 @@ private fun FeatureThatRequiresCameraPermission() {
android.Manifest.permission.CAMERA
)

when (cameraPermissionState.status) {
// If the camera permission is granted, then show screen with the feature enabled
PermissionStatus.Granted -> {
Text("Camera permission Granted")
}
is PermissionStatus.Denied -> {
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")
}
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")
}
}
}
Expand All @@ -66,6 +63,13 @@ private fun FeatureThatRequiresCameraPermission() {

For more examples, refer to the [samples](https://github.com/google/accompanist/tree/main/sample/src/main/java/com/google/accompanist/sample/permissions).

## Limitations

This permissions wrapper is built on top of the available Android platform APIs. We cannot extend
the platform's capabilities. For example, it's not possible to differentiate the between the
_it's the first time requesting the permission_ vs _the user doesn't want to be asked again_
use cases.

## Download

[![Maven Central](https://img.shields.io/maven-central/v/com.google.accompanist/accompanist-permissions)](https://search.maven.org/search?q=g:com.google.accompanist)
Expand Down

0 comments on commit 916e1bb

Please sign in to comment.