rememberCaptureMediaLauncher
Creates and remembers a process-death-safe launcher for capturing media (photo and/or video) using the device camera.
Destination file paths are persisted via rememberSaveable. When the hosting activity is destroyed and recreated (e.g. under "Don't keep activities"), the paths are restored on the CaptureMediaContract before the pending result is delivered, ensuring the captured file is correctly resolved.
Return
A ManagedActivityResultLauncher that can be used to launch the media capture activity, or null if both photo and video are false (no valid capture mode). The launcher accepts Unit as input and produces a nullable File as output.
Parameters
Callback invoked when media capture completes successfully. Receives a File representing the captured media. This callback is only invoked if the user successfully captures media; it is not called if the user cancels the capture.
See also
Example usage:
val captureMediaLauncher = rememberCaptureMediaLauncher(
photo = true,
video = true,
onResult = { file ->
// Handle captured media file
}
)
// Launch the camera
captureMediaLauncher?.launch(Unit)Note: This function doesn't check for camera permissions. Ensure that the necessary permissions are granted before invoking the launcher.