0Pricing
Android Academy · Lesson

Requesting Permissions in Compose

Use the Accompanist or activity result APIs.

Requesting Permissions in Compose is a free Android Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Android Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Requesting in Compose

In Jetpack Compose you request runtime permissions using the Activity Result API, wrapped by rememberLauncherForActivityResult. This avoids the old onRequestPermissionsResult callback.

The RequestPermission Contract

The Activity Result API uses contracts that define input and output. ActivityResultContracts.RequestPermission() takes a permission string and returns a Boolean grant result.

Creating a Launcher

rememberLauncherForActivityResult creates a launcher tied to the composition. You pass the contract and a callback that receives the result.

val launcher = rememberLauncherForActivityResult(
    contract = ActivityResultContracts.RequestPermission()
) { isGranted ->
    if (isGranted) {
        // permission granted, use the feature
    } else {
        // permission denied
    }
}

Launching the Request

Call launcher.launch with the permission you want. The system shows its dialog, and your callback fires with the user choice.

Button(onClick = {
    launcher.launch(Manifest.permission.CAMERA)
}) {
    Text("Enable Camera")
}

Check Before You Ask

Do not blindly launch a request. First check whether the permission is already granted, and only request if it is not.

val context = LocalContext.current
val alreadyGranted = ContextCompat.checkSelfPermission(
    context, Manifest.permission.CAMERA
) == PackageManager.PERMISSION_GRANTED

Tracking State in Compose

Hold the current grant status in state so the UI can react. Update it inside the launcher callback.

var hasCamera by remember {
    mutableStateOf(
        ContextCompat.checkSelfPermission(
            context, Manifest.permission.CAMERA
        ) == PackageManager.PERMISSION_GRANTED
    )
}

val launcher = rememberLauncherForActivityResult(
    ActivityResultContracts.RequestPermission()
) { granted -> hasCamera = granted }

Requesting Multiple Permissions

For several permissions at once, use the RequestMultiplePermissions contract. The callback receives a map of permission to grant status.

val multi = rememberLauncherForActivityResult(
    ActivityResultContracts.RequestMultiplePermissions()
) { results ->
    val fineLocation = results[Manifest.permission.ACCESS_FINE_LOCATION] == true
}

multi.launch(
    arrayOf(
        Manifest.permission.ACCESS_FINE_LOCATION,
        Manifest.permission.ACCESS_COARSE_LOCATION
    )
)

Driving the UI From State

Show different content based on the grant state: if granted, show the feature; otherwise show a button to request it. This keeps the screen reactive and clear.

if (hasCamera) {
    CameraPreview()
} else {
    Button(onClick = { launcher.launch(Manifest.permission.CAMERA) }) {
        Text("Grant camera access")
    }
}

The Accompanist Permissions Option

The Accompanist Permissions library offers higher-level helpers like rememberPermissionState. Many teams prefer the raw Activity Result API to avoid an extra dependency; both are valid.

Do Not Request on Launch

Avoid firing a permission request the instant a screen appears. Wait until the user taps an action that clearly needs it. Context-driven requests get far higher grant rates.

Remember Configuration Changes

rememberLauncherForActivityResult survives recomposition, and the Activity Result framework correctly delivers results even across configuration changes like rotation. You do not manage that plumbing yourself.

Quick Check

Test your understanding of requesting permissions.

Recap

You requested permissions the modern way:

  • Use rememberLauncherForActivityResult with the RequestPermission contract
  • Check first, then launcher.launch(permission)
  • Track grant status in state to drive the UI
  • Use RequestMultiplePermissions for several at once

Next: handling denials and showing rationale.

Frequently asked questions

Is the “Requesting Permissions in Compose” lesson free?

Yes — the full text of “Requesting Permissions in Compose” is free to read here on the web, and the Android Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Android Academy course, upgrade to CoddyKit PRO.

What will I learn in “Requesting Permissions in Compose”?

Use the Accompanist or activity result APIs. You practise Android Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Android Academy?

No prior experience is required. Android Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Requesting Permissions in Compose” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Android Academy lesson?

Yes. Every Android Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. The Android Permission Model
  2. Requesting Permissions in Compose
  3. Handling Denials and Rationale
  4. Best Practices for Privacy
← Back to Android Academy