google/accompanist

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

lupsyn opened this issue · 6 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]

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.

how it's goin ?

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

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