> ## Documentation Index
> Fetch the complete documentation index at: https://filekit.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Camera picker

> Take a photo with the device camera and get it back as a PlatformFile on Android and iOS

[See the platform support matrix](https://filekit.mintlify.site/platform-support.md#filekit-dialogs)

Open the system camera to take a photo. FileKit writes the photo to a file and returns it as a `PlatformFile`. Call it from a source set that only includes Android and iOS, such as `mobileMain` (see [shared source sets](https://filekit.mintlify.site/platform-support.md#use-platform-specific-apis-from-shared-code)).

## Usage

```kotlin Compose theme={null}
val launcher = rememberCameraPickerLauncher(
    onError = { failure -> showError(failure.message) },
) { photo ->
    // photo is a PlatformFile, or null if the user cancelled
}

Button(onClick = { launcher.launch() }) {
    Text("Take a photo")
}
```

```kotlin Suspend API theme={null}
val photo: PlatformFile? = FileKit.openCameraPicker()
```

The result is `null` when the user cancels. Failures go to `onError` in Compose, or are thrown as a `FileKitDialogException` by the suspend API. See [Results and errors](https://filekit.mintlify.site/dialogs/error-handling.md).

## Options

**type** `FileKitCameraType` (default: Photo)

What to capture. Only `Photo` is available: video capture is not supported yet.

**cameraFacing** `FileKitCameraFacing` (default: System)

`System` lets the camera app choose, or force `Front` or `Back`. Best effort on Android: see [Platform notes](#platform-notes).

**destinationFile** `PlatformFile` (default: FileKit.cacheDir / "\<random UUID>.jpg")

Where the photo is written. Files in `filesDir` and `cacheDir` need no Android setup.

**openCameraSettings** `FileKitOpenCameraSettings` (default: createDefault())

Platform-specific settings. In the suspend API, pass it to `openCameraPicker()`.

**properties**

**authority** `String?` (default: null)

FileProvider authority, only needed for a `destinationFile` outside `filesDir` and `cacheDir`. When `null`, FileKit uses its bundled `${applicationId}.FileKitFileProvider`. See [Android setup](#android-setup).

**presenter** `UIViewController?` (default: null)

View controller that presents the camera. When `null`, the suspend API presents from its own window above your app, and the Compose launcher uses the current `LocalUIViewController`.

## Keep the photo

The default destination is in the cache directory, which the system can clear. To keep the photo, write it to `FileKit.filesDir` directly:

```kotlin theme={null}
val photo = FileKit.openCameraPicker(
    destinationFile = FileKit.filesDir / "profile.jpg",
)
```

Files in `FileKit.filesDir` and `FileKit.cacheDir` need no Android setup. For any other directory, see [Android setup](#android-setup).

## Platform notes

| Platform | Behavior |
| - | - |
| Android | Launches the device camera app with `ACTION_IMAGE_CAPTURE`. If your manifest declares `android.permission.CAMERA`, FileKit requests it before opening the camera, and a denial returns `null`. If you don't declare it, no permission is needed. |
| Android | `Front` and `Back` are best effort. Android has no standard extra to choose the camera, so FileKit sends the extras that common camera apps read. Some devices ignore them. |
| iOS | Add `NSCameraUsageDescription` to your `Info.plist`: iOS terminates apps that open the camera without it. |
| iOS | The photo is saved as a full-quality JPEG. A missing camera (such as the Simulator) or an unavailable `Front` or `Back` camera fails with a `FileKitDialogException`. |

## Android setup

Only needed for files outside `FileKit.filesDir` and `FileKit.cacheDir`. `filekit-dialogs` already ships a FileProvider (`${applicationId}.FileKitFileProvider`) that covers those two directories, and `content://` files returned by the pickers need no provider at all. For any other location, such as `getExternalFilesDir()`, `FileProvider` throws an `IllegalArgumentException` until you declare your own provider.

**1. Declare a provider in your manifest**

```xml AndroidManifest.xml theme={null}
<provider
    android:name="androidx.core.content.FileProvider"
    android:authorities="${applicationId}.fileprovider"
    android:exported="false"
    android:grantUriPermissions="true">
    <meta-data
        android:name="android.support.FILE_PROVIDER_PATHS"
        android:resource="@xml/file_paths" />
</provider>
```

**2. List the directories it may expose**

Add one entry per location you use, for example app-specific external storage:

```xml res/xml/file_paths.xml theme={null}
<paths>
    <external-files-path name="external_files" path="." />
</paths>
```

See [FileProvider](https://developer.android.com/reference/androidx/core/content/FileProvider) for every path type.

**3. Pass the authority to FileKit**

The `authority` parameter exists only on Android, so build these settings in `androidMain`:

```kotlin androidMain theme={null}
val authority = "${FileKit.context.packageName}.fileprovider"

FileKitOpenCameraSettings(authority = authority) // camera picker
FileKitShareSettings(authority = authority) // share file
FileKitOpenFileSettings(authority = authority) // open with default app
```

For example, to save to app-specific external storage:

```kotlin androidMain theme={null}
val externalDir = PlatformFile(FileKit.context.getExternalFilesDir(null)!!)

val photo = FileKit.openCameraPicker(
    destinationFile = externalDir / "photo.jpg",
    openCameraSettings = FileKitOpenCameraSettings(
        authority = "${FileKit.context.packageName}.fileprovider",
    ),
)
```

With Compose, pass the same `openCameraSettings` to `rememberCameraPickerLauncher` and the file to `launch(destinationFile = ...)`.

## Related

* [Gallery picker](https://filekit.mintlify.site/dialogs/gallery-picker.md) to pick existing photos.
* [Share file](https://filekit.mintlify.site/dialogs/share-file.md) to send the photo to another app.
* [Results and errors](https://filekit.mintlify.site/dialogs/error-handling.md) for cancellation and failure handling.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.