CaptureMediaContract

class CaptureMediaContract(mode: CaptureMediaContract.Mode, fileManager: StreamFileManager = StreamFileManager(), onFilesCreated: (pictureFile: File?, videoFile: File?) -> Unit? = null) : ActivityResultContract<Unit, File?>

Activity result contract for capturing media (photos and/or videos) using the device camera.

Files are created in external storage directories:

  • Photos: {externalFilesDir}/Pictures/

  • Videos: {externalFilesDir}/Movies/ With fallback to cache directories if external storage is unavailable.

pictureFile and videoFile are set during createIntent and used by parseResult to resolve the captured file. After process death these references are lost; callers can restore them via restoreFilePaths before the pending result is dispatched.

Parameters

mode

The capture mode determining what media types can be captured.

fileManager

Manager for creating temporary files in external storage.

onFilesCreated

Optional callback invoked inside createIntent after destination files are created, giving the caller an opportunity to persist the file references before the external activity starts.

Constructors

Link copied to clipboard
constructor(mode: CaptureMediaContract.Mode, fileManager: StreamFileManager = StreamFileManager(), onFilesCreated: (pictureFile: File?, videoFile: File?) -> Unit? = null)

Types

Link copied to clipboard

Functions

Link copied to clipboard
open override fun createIntent(context: Context, input: Unit): Intent
Link copied to clipboard
open override fun parseResult(resultCode: Int, intent: Intent?): File?
Link copied to clipboard
fun restoreFilePaths(picturePath: String?, videoPath: String?)

Restores pictureFile and videoFile from previously persisted absolute paths.