Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onPermissionsResult isn't triggered on POST_NOTIFICATIONS permission request (API 33). #1740

Open
lupsyn opened this issue Jan 18, 2024 · 6 comments

Comments

@lupsyn
Copy link

lupsyn commented Jan 18, 2024

Describe the bug

onPermissionsResult call back isn't triggered on android.permission.POST_NOTIFICATIONS on allow/deny (API 33)

To Reproduce

Use a generic impl as the following one to trigger the permission request.

fun UiContent.toPermissionDialog(
    rationale: @Composable () -> Unit = { },
    onPermissionResultCallback: (allPermissionsGranted: Boolean) -> Unit = {},
) {
    val permissionState = rememberMultiplePermissionsState(
        permissions = permissions,
        onPermissionsResult = { permissionGrantMap ->
        
            onPermissionResultCallback(permissionGrantMap.values.all { it })
        }
    )

    if (permissionState.allPermissionsGranted) {
        onPermissionResultCallback(true)
    } else {
        if (permissionState.shouldShowRationale) {
            rationale.invoke()
        }
    
        LaunchedEffect(key1 = this) {
            permissionState.launchMultiplePermissionRequest()
        }
    }
}

Expected behavior

onPermissionsResult should be triggered

Environment:

  • Android OS version: [API 33]
  • Device: [every device]
  • Accompanist version: [0.33.2-alpha]
Copy link

github-actions bot commented Mar 5, 2024

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the stale Stale issues which are marked for closure label Mar 5, 2024
@ianhanniballake ianhanniballake removed the stale Stale issues which are marked for closure label Mar 8, 2024
@chubecode
Copy link

how it's goin ?

@sprokipchyn
Copy link

same with CAMERA permission request. Is there any benefit of this library if I cannot get back any result of permission request?

@PrimoDev23
Copy link

This seems to work just fine for both permission types when using the attached code. Anyways the attached code is not following best practices, since you are calling a normal function in a compose context, which might result in calling it every recomposition.
You should prefer something like this

val permissionState = rememberMultiplePermissionsState(
      permissions = listOf(Manifest.permission.CAMERA),
      onPermissionsResult = { result ->
          val allGranted = result.values.all { it }
      
          if (allGranted) {
              println("GRANTED")
          } else {
              println("DENIED")
          }
      }
)
      
if (permissionState.shouldShowRationale) {
      Text(
          modifier = Modifier.clickable {
              permissionState.launchMultiplePermissionRequest()
          },
          text = "PLEASE OBI WAN, GIVE ME SOME POWER!"
      )
} else if (!permissionState.allPermissionsGranted) {
      LaunchedEffect(Unit) {
          permissionState.launchMultiplePermissionRequest()
      }
}

@sprokipchyn
Copy link

@PrimoDev23 I have the exact code and for some reason onPermissionsResult is not being called. So I see the standard permission popup (camera in my case). I click Allow for this time only and that's it: popup disappears, nothing happens, the callback is not triggered. Interesting fact: next time I call this code - permission is already granted and I can use the camera.

@PrimoDev23
Copy link

@PrimoDev23 I have the exact code and for some reason onPermissionsResult is not being called. So I see the standard permission popup (camera in my case). I click Allow for this time only and that's it: popup disappears, nothing happens, the callback is not triggered. Interesting fact: next time I call this code - permission is already granted and I can use the camera.

It's quite unclear why this is happening. Did you test this using the emulator? I tested this with API 34 and 33 and it worked just fine in both cases for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants