Search code examples
androidcallbackandroid-jetpack-composeandroid-permissionsjetpack-compose-accompanist

Is there a callback function for launchPermission in the Accompanist library


Is there a callback function after executing permissionState.launchPermissionRequest() in the Accompanist Permissions library? I want to execute some code only after it finishes.


Solution

  • A more straight forward way is to use the rememberMultiplePermissionsState's or rememberPermissionState's onPermissionsResult or onPermissionResult callback function as documented in the API documentation and as shown below:

    permissionsToRequest = listOf(                         
       Manifest.permission.READ_EXTERNAL_STORAGE,
       Manifest.permission.CAMERA,
    )
    
    val multiplePermissionsState = 
       rememberMultiplePermissionsState(permissions = permissionsToRequest) {            
          //will be called with whether or not the user granted the permissions
    }