> ## 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 dialog

> Open a camera picker dialog in a Kotlin Multiplatform project

<Check>Supported on Android and iOS targets</Check>

## Quick start

The camera picker component provides a native interface for users to capture photos using their device's camera.

<CodeGroup>
  ```kotlin filekit-dialogs theme={null}
  val file = FileKit.openCameraPicker()
  ```

  ```kotlin filekit-dialogs-compose theme={null}
  val launcher = rememberCameraPickerLauncher { file ->
      // Handle the captured photo
  }

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

The captured media file is automatically saved to the specified location (or cache directory by default). If you need to keep the file permanently, make sure to copy it to a permanent storage location.

## Android camera permission behavior

On Android, camera capture is launched with `ACTION_IMAGE_CAPTURE`.
If your app declares `android.permission.CAMERA`, FileKit checks runtime permission before launching the camera:

* If camera permission is already granted, FileKit opens the camera as usual.
* If camera permission is not granted, FileKit requests it first.
* If the user denies the permission, FileKit returns `null` (same as cancel) and does not crash.

If your app only launches the external camera app through this picker, you usually do not need to declare `android.permission.CAMERA`.

## Camera type

You can specify the type of media to capture using the `type` parameter:

* `Photo` - Capture a photo (default)
* `Video` - Capture a video (coming soon)

<CodeGroup>
  ```kotlin filekit-dialogs theme={null}
  val file = FileKit.openCameraPicker(type = FileKitCameraType.Photo)
  ```

  ```kotlin filekit-dialogs-compose theme={null}
  val launcher = rememberCameraPickerLauncher { file ->
      // Handle the captured photo
  }

  Button(onClick = { launcher.launch(type = FileKitCameraType.Photo) }) {
      Text("Take a photo")
  }
  ```
</CodeGroup>

<Info>
  Video capture support is planned for a future release.
</Info>

## Camera facing

You can specify whether the front or rear facing camera is used, using the `cameraFacing` parameter:

* `System` lets the camera app decide which camera to open (default)
* `Front` opens the front facing camera (Selfie-Camera)
* `Back` opens the rear facing camera

By default, the camera app decides which camera to use.
On Android, FileKit only applies camera-facing intent extras when you explicitly request `Front` or `Back`.

<CodeGroup>
  ```kotlin filekit-dialogs theme={null}
  val file = FileKit.openCameraPicker(cameraFacing = FileKitCameraFacing.Front)
  ```

  ```kotlin filekit-dialogs-compose theme={null}
  val launcher = rememberCameraPickerLauncher { file ->
      // Handle the captured photo
  }

  Button(onClick = { launcher.launch(cameraFacing = FileKitCameraFacing.Front) }) {
      Text("Take a selfie")
  }
  ```
</CodeGroup>

<Warning>
  Android has no documented parameter for an intent to specify which camera is supposed to be used by the Camera App.
  Since Android implementations differ, we can not guarantee that this feature will work for every device/Android version.
  If you encounter issues please file an issue.
</Warning>

## Destination file

You can specify where the captured photo should be saved using the `destinationFile` parameter. By default, the photo is saved to the cache directory with a randomly generated filename.

<CodeGroup>
  ```kotlin filekit-dialogs theme={null}
  // Using default destination (cache directory with random filename)
  val file = FileKit.openCameraPicker()

  // Specifying a custom destination
  val customFile = FileKit.filesDir / "my_photo.jpg"
  val file = FileKit.openCameraPicker(destinationFile = customFile)
  ```

  ```kotlin filekit-dialogs-compose theme={null}
  val launcher = rememberCameraPickerLauncher { file ->
      // Handle the captured photo
  }

  // Using default destination
  Button(onClick = { launcher.launch() }) {
      Text("Take a photo")
  }

  // Specifying a custom destination
  val customFile = FileKit.filesDir / "my_photo.jpg"
  Button(onClick = { launcher.launch(destinationFile = customFile) }) {
      Text("Take a photo to custom location")
  }
  ```
</CodeGroup>

<Warning>
  On Android, when using a custom `destinationFile`, you must provide the `openCameraSettings` parameter with your app's FileProvider authority. This ensures the camera app has permission to write to your specified location.
</Warning>

## Destination file Android Setup

Opening files on Android requires additional FileProvider configuration to securely share files with other applications. Starting from Android 7.0 (API level 24), Android restricts the sharing of file URIs between apps for security reasons. FileProvider generates secure content URIs that allow temporary access to specific files.

**Why FileProvider is required?**

Android uses FileProvider to:

* **Enhance security**: Prevents exposing your app's internal file structure to other apps
* **Control access**: Grants temporary, limited access to specific files only
* **Maintain compatibility**: Required for opening files on Android 7.0+ due to `FileUriExposedException`

When using custom file locations on Android, you need to configure a FileProvider in your app:

<Info>
  For detailed information about FileProvider, see the [official Android documentation](https://developer.android.com/reference/androidx/core/content/FileProvider).
</Info>

1. Add the FileProvider to your `AndroidManifest.xml`:

```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. Create `androidMain/res/xml/file_paths.xml`:

```xml theme={null}
<paths>
    <cache-path name="filekit_cache" path="." />
    <files-path name="filekit_files" path="." />
</paths>
```

<Info>
  **Important**: Include only the path type that matches your FileKit usage:

  * Use `<files-path>` if you use `FileKit.filesDir`
  * Use `<cache-path>` if you use `FileKit.cacheDir`
  * Include both if you use both directories
</Info>

3. When using a custom `destinationFile`, provide the `openCameraSettings` parameter with your app's FileProvider authority:

<CodeGroup>
  ```kotlin filekit-dialogs theme={null}
  val customFile = FileKit.filesDir / "my_photo.jpg"
  val file = FileKit.openCameraPicker(
      destinationFile = customFile,
      openCameraSettings = FileKitOpenCameraSettings(
          authority = "${context.packageName}.fileprovider"
      )
  )
  ```

  ```kotlin filekit-dialogs-compose theme={null}
  val customFile = FileKit.filesDir / "my_photo.jpg"
  Button(onClick = { 
      launcher.launch(
          destinationFile = customFile,
          openCameraSettings = FileKitOpenCameraSettings(
              authority = "${context.packageName}.fileprovider"
          )
      )
  }) {
      Text("Take a photo to custom location")
  }
  ```
</CodeGroup>
