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:
Checks if permissions are already granted (and returns early if so)
Requests permissions if not granted
Automatically opens app settings if permissions are denied
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()
}
)
}
}Content copied to clipboard
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