accompanist icon indicating copy to clipboard operation
accompanist copied to clipboard

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

Open lupsyn opened this issue 1 year ago • 4 comments

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]

lupsyn avatar Jan 18 '24 15:01 lupsyn

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[bot] avatar Mar 05 '24 03:03 github-actions[bot]

how it's goin ?

begiflow avatar Apr 19 '24 08:04 begiflow

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

sprokipchyn avatar May 13 '24 18:05 sprokipchyn

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()
      }
}

PrimoDev23 avatar May 16 '24 08:05 PrimoDev23

@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.

sprokipchyn avatar May 22 '24 15:05 sprokipchyn

@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

PrimoDev23 avatar May 22 '24 19:05 PrimoDev23

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[bot] avatar Jul 07 '24 03:07 github-actions[bot]