Supported on Android and iOS targets
Quick start
The camera picker component provides a native interface for users to capture photos using their device’s camera.onError receives a FileKitDialogException only when FileKit cannot start or complete a valid camera operation, such as when no Android camera activity is available or iOS cannot prepare, present, encode, or write the capture. User dismissal is not a failure and invokes onResult(null). Android camera-permission denial also invokes onResult(null). Coroutine cancellation, invalid invocation, and unexpected defects continue to propagate normally.
The suspending FileKit.openCameraPicker() function throws the same FileKitDialogException for operational failures. On Android, this includes an unavailable or unauthorized camera-permission request or camera launch. On iOS, this includes failures while preparing, presenting, encoding, or writing the capture. Android’s lifecycle-safe Compose launcher reports the equivalent launch failures through onError. The compatibility Compose overload without onError remains available and ignores normalized operational failures without logging. New integrations should use explicit error handling.
See dialog error handling for the complete callback and propagation matrix.
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 withACTION_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.
android.permission.CAMERA.
Camera type
You can specify the type of media to capture using thetype parameter:
Photo- Capture a photo (default)Video- Capture a video (coming soon)
Video capture support is planned for a future release.
Camera facing
You can specify whether the front or rear facing camera is used, using thecameraFacing parameter:
Systemlets the camera app decide which camera to open (default)Frontopens the front facing camera (Selfie-Camera)Backopens the rear facing camera
Front or Back.
Destination file
You can specify where the captured photo should be saved using thedestinationFile parameter. By default, the photo is saved to the cache directory with a randomly generated filename.
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
For detailed information about FileProvider, see the official Android documentation.
- Add the FileProvider to your
AndroidManifest.xml:
- Create
androidMain/res/xml/file_paths.xml:
Important: Include only the path type that matches your FileKit usage:
- Use
<files-path>if you useFileKit.filesDir - Use
<cache-path>if you useFileKit.cacheDir - Include both if you use both directories
- When using a custom
destinationFile, provide theopenCameraSettingsparameter with your app’s FileProvider authority: