Skip to main content
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).

Usage

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.

Options

FileKitCameraType
default:"Photo"
launch()
What to capture. Only Photo is available: video capture is not supported yet.
FileKitCameraFacing
default:"System"
launch()
System lets the camera app choose, or force Front or Back. Best effort on Android: see Platform notes.
PlatformFile
default:"FileKit.cacheDir / \"<random UUID>.jpg\""
launch()
Where the photo is written. Files in filesDir and cacheDir need no Android setup.
FileKitOpenCameraSettings
default:"createDefault()"
rememberCameraPickerLauncher
Platform-specific settings. In the suspend API, pass it to openCameraPicker().

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:
Files in FileKit.filesDir and FileKit.cacheDir need no Android setup. For any other directory, see Android setup.

Platform notes

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

AndroidManifest.xml
2

List the directories it may expose

Add one entry per location you use, for example app-specific external storage:
res/xml/file_paths.xml
See FileProvider for every path type.
3

Pass the authority to FileKit

The authority parameter exists only on Android, so build these settings in androidMain:
androidMain
For example, to save to app-specific external storage:
androidMain
With Compose, pass the same openCameraSettings to rememberCameraPickerLauncher and the file to launch(destinationFile = ...).