checkForPermissions

inline fun ComponentActivity.checkForPermissions(permissions: List<String>, crossinline onSuccess: () -> Unit)

Checks and requests permissions with automatic settings navigation on denial.

This is a high-level permission helper that:

  1. Checks if permissions are already granted (and returns early if so)

  2. Requests permissions if not granted

  3. Automatically opens app settings if permissions are denied

  4. Shows a toast message prompting the user to grant permissions

Usage

class CameraActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

checkForPermissions(
permissions = listOf(
Manifest.permission.CAMERA,
Manifest.permission.WRITE_EXTERNAL_STORAGE
),
onSuccess = {
initializeCamera()
}
)
}
}

Behavior on Denial

If the user denies permissions:

  • Shows toast: "PLEASE ALLOW ALL PERMISSIONS"

  • Automatically opens app settings via openPermissionSettings

  • User must manually grant permissions in settings

Parameters

permissions

List of Android permission strings to request

onSuccess

Callback invoked when all permissions are granted

See also