# SessionConfig.Builder

Artifact: [androidx.camera:camera-core](https://developer.android.com/jetpack/androidx/releases/camera) [View Source](https://cs.android.com/search?q=file:androidx/camera/core/SessionConfig.kt+class:androidx.camera.core.SessionConfig.Builder) Added in [1.5.0](https://developer.android.com/jetpack/androidx/releases/camera#1.5.0)

*** ** * ** ***


```
@CameraXDsl
class SessionConfig.Builder
```

<br />

*** ** * ** ***

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig.Builder#Builder(kotlin.collections.List)(useCases: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/camera/core/UseCase>)` |
| `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig.Builder#Builder(kotlin.Array)(vararg useCases: https://developer.android.com/reference/kotlin/androidx/camera/core/UseCase)` |

| ### Public functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig.Builder` | `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig.Builder#addEffect(androidx.camera.core.CameraEffect)(effect: https://developer.android.com/reference/kotlin/androidx/camera/core/CameraEffect)` Adds a `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraEffect` to be applied on the camera session. |
| `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig` | `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig.Builder#build()()` Builds a `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig` from the current configuration. |
| `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig.Builder` | `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig.Builder#setAutoRotationEnabled(kotlin.Boolean)(autoRotationEnabled: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` Sets whether to use auto rotation. |
| `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig.Builder` | `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig.Builder#setFrameRateRange(android.util.Range)(frameRateRange: https://developer.android.com/reference/android/util/Range.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html>)` Sets the frame rate range for the camera session. |
| `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig.Builder` | `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig.Builder#setInterop(androidx.camera.core.InteropConfigurator)(configurator: https://developer.android.com/reference/kotlin/androidx/camera/core/InteropConfigurator<https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig.Builder>)` Applies interoperability configuration to this builder. |
| `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig.Builder` | `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig.Builder#setPreferredFeatureGroup(kotlin.Array)(vararg features: https://developer.android.com/reference/kotlin/androidx/camera/core/featuregroup/GroupableFeature)` Sets the list of preferred `https://developer.android.com/reference/kotlin/androidx/camera/core/featuregroup/GroupableFeature`, ordered by priority in descending order. |
| `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig.Builder` | `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig.Builder#setRequiredFeatureGroup(kotlin.Array)(vararg features: https://developer.android.com/reference/kotlin/androidx/camera/core/featuregroup/GroupableFeature)` Sets the list of `https://developer.android.com/reference/kotlin/androidx/camera/core/featuregroup/GroupableFeature` that are mandatory for the camera configuration. |
| `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig.Builder` | `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig.Builder#setViewPort(androidx.camera.core.ViewPort)(viewPort: https://developer.android.com/reference/kotlin/androidx/camera/core/ViewPort)` Sets the `https://developer.android.com/reference/kotlin/androidx/camera/core/ViewPort` to be applied on the camera session. |

| ### Extension functions |
|---|---|
| `inline https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig.Builder` | `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig.Builder.https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig.Builder#(androidx.camera.core.SessionConfig.Builder).camera2Interop(kotlin.Function1)(crossinline block: https://developer.android.com/reference/kotlin/androidx/camera/camera2/interop/SessionConfigCamera2Interop.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)` Applies Camera2 options to a `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig.Builder`. |

## Public constructors

### Builder

```
Builder(useCases: List<UseCase>)
```

### Builder

Added in [1.5.0](https://developer.android.com/jetpack/androidx/releases/camera#1.5.0)

```
Builder(vararg useCases: UseCase)
```

## Public functions

### addEffect

Added in [1.5.0](https://developer.android.com/jetpack/androidx/releases/camera#1.5.0)

```
fun addEffect(effect: CameraEffect): SessionConfig.Builder
```

Adds a `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraEffect` to be applied on the camera session.

### build

Added in [1.5.0](https://developer.android.com/jetpack/androidx/releases/camera#1.5.0)

```
fun build(): SessionConfig
```

Builds a `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig` from the current configuration.

### setAutoRotationEnabled

Added in [1.7.0-rc02](https://developer.android.com/jetpack/androidx/releases/camera#1.7.0-rc02)

```
fun setAutoRotationEnabled(autoRotationEnabled: Boolean): SessionConfig.Builder
```

Sets whether to use auto rotation.

When enabled, CameraX will monitor the device motion sensor and set the target rotation for ImageCapture, VideoCapture and ImageAnalysis.

### setFrameRateRange

Added in [1.5.0](https://developer.android.com/jetpack/androidx/releases/camera#1.5.0)

```
fun setFrameRateRange(frameRateRange: Range<Int>): SessionConfig.Builder
```

Sets the frame rate range for the camera session.

See `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig#frameRateRange()` for more details.

| Parameters |
|---|---|
| `frameRateRange: https://developer.android.com/reference/android/util/Range.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html>` | The frame rate range to be applied on the camera session. |

### setInterop

Added in [1.7.0-rc02](https://developer.android.com/jetpack/androidx/releases/camera#1.7.0-rc02)

```
fun setInterop(configurator: InteropConfigurator<SessionConfig.Builder>): SessionConfig.Builder
```

Applies interoperability configuration to this builder.

To configure Camera2 options, use `https://developer.android.com/reference/kotlin/androidx/camera/camera2/interop/Camera2Interop#forSessionConfig(androidx.core.util.Consumer)` (from the `camera-camera2` artifact) to create a configurator, then pass it to this method.

**Note:** Using Camera2 interop options can override internal CameraX configurations. If an option configured via interop conflicts with options required by CameraX internally, the option from Camera2Interop will override, which may result in unexpected behavior.

**Warning:** Callbacks configured via interop receive raw `https://developer.android.com/reference/android/hardware/camera2/CameraDevice.html` and `https://developer.android.com/reference/android/hardware/camera2/CameraCaptureSession.html` instances. Directly invoking state-altering methods on these raw objects (such as `https://developer.android.com/reference/android/hardware/camera2/CameraCaptureSession.html#close()`, `https://developer.android.com/reference/android/hardware/camera2/CameraCaptureSession.html#abortCaptures()`, or `https://developer.android.com/reference/android/hardware/camera2/CameraDevice.html#close()`) bypasses CameraX pipeline management and may cause state desynchronization, stream interruption, or application crashes.

| Parameters |
|---|---|
| `configurator: https://developer.android.com/reference/kotlin/androidx/camera/core/InteropConfigurator<https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig.Builder>` | the configurator that sets the interoperability options |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig.Builder` | this builder |

### setPreferredFeatureGroup

Added in [1.5.0](https://developer.android.com/jetpack/androidx/releases/camera#1.5.0)

```
fun setPreferredFeatureGroup(vararg features: GroupableFeature): SessionConfig.Builder
```

Sets the list of preferred `https://developer.android.com/reference/kotlin/androidx/camera/core/featuregroup/GroupableFeature`, ordered by priority in descending order.

Features are evaluated for support based on this specified priority. The feature with a lower index (listed first) is considered higher priority. The system attempts to enable preferred features on a best-effort basis:

- It starts with the highest priority feature.

- If a feature is supported (considering device capabilities and any other already selected preferred features or required features), it's added to the selection.

- If a preferred feature is *not* supported, it's skipped, and the system proceeds to evaluate the next feature in the preferred list.

For example, consider the following scenarios where `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig#requiredFeatureGroup()` is empty:

|---|---|---|
| Preferred List | Device Support | Selected Features |
| `[HDR_HLG10, FPS_60, ULTRA_HDR]` | HLG10 + 60 FPS not supported | `[HDR_HLG10, ULTRA_HDR]` |
| `[FPS_60, HDR_HLG10, ULTRA_HDR]` | HLG10 + 60 FPS not supported | `[FPS_60, ULTRA_HDR]` |
| `[HDR_HLG10, FPS_60, ULTRA_HDR]` | HLG10 is not supported | `[FPS_60, ULTRA_HDR]` |
| `[HDR_HLG10, FPS_60]` | Both supported together | `[HDR_HLG10, FPS_60]` |

The final set of selected features will be notified to the listener set by the `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig#setFeatureSelectionListener(java.util.concurrent.Executor,androidx.core.util.Consumer)` API.

See the `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig` documentation for all of the constraints related to this API.

| Parameters |
|---|---|
| `vararg features: https://developer.android.com/reference/kotlin/androidx/camera/core/featuregroup/GroupableFeature` | The list of preferred features, ordered by preference. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig.Builder` | The `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig.Builder` instance, allowing for method chaining. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/core/featuregroup/GroupableFeature` |   |
| `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig` |   |

### setRequiredFeatureGroup

Added in [1.5.0](https://developer.android.com/jetpack/androidx/releases/camera#1.5.0)

```
fun setRequiredFeatureGroup(vararg features: GroupableFeature): SessionConfig.Builder
```

Sets the list of `https://developer.android.com/reference/kotlin/androidx/camera/core/featuregroup/GroupableFeature` that are mandatory for the camera configuration.

If any of the features is not supported or if the features are not supported together as a combination, an `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` will be thrown when the `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig` is bound to a lifecycle (e.g. when the `androidx.camera.lifecycle.ProcessCameraProvider.bindToLifecycle` API is invoked).

To avoid setting an unsupported feature as required, the `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig.Builder#setPreferredFeatureGroup(kotlin.Array)` API can be used since the features from the preferred features are selected on a best-effort basis according to the priority defined by the ordering of features in the list. Alternatively, the `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraInfo#isSessionConfigSupported(androidx.camera.core.SessionConfig)` API can be used before binding to check if the features are supported or not.

Unlike the `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig.Builder#setPreferredFeatureGroup(kotlin.Array)` API, the order of the features doesn't matter for this API since each and every one of these features must be configured.

See the `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig` documentation for all of the constraints related to this API.

| Parameters |
|---|---|
| `vararg features: https://developer.android.com/reference/kotlin/androidx/camera/core/featuregroup/GroupableFeature` | The vararg of `GroupableFeature` objects to add to the required features. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig.Builder` | The `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig.Builder` instance, allowing for method chaining. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/core/featuregroup/GroupableFeature` |   |

### setViewPort

Added in [1.5.0](https://developer.android.com/jetpack/androidx/releases/camera#1.5.0)

```
fun setViewPort(viewPort: ViewPort): SessionConfig.Builder
```

Sets the `https://developer.android.com/reference/kotlin/androidx/camera/core/ViewPort` to be applied on the camera session.

## Extension functions

### SessionConfig.Builder.camera2Interop

Artifact: [androidx.camera:camera-camera2](https://developer.android.com/jetpack/androidx/releases/camera) [View Source](https://cs.android.com/search?q=file:androidx/camera/camera2/interop/Camera2InteropEx.kt+function:camera2Interop)

```
inline fun SessionConfig.Builder.camera2Interop(crossinline block: SessionConfigCamera2Interop.() -> Unit): SessionConfig.Builder
```

Applies Camera2 options to a `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig.Builder`.

Configures Camera2 options for a capture session builder. Can be called on a `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig.Builder` directly or within a `https://developer.android.com/reference/kotlin/androidx/camera/core/package-summary#sessionConfig(kotlin.collections.List,kotlin.Function1)` DSL block.

Options configured via `https://developer.android.com/reference/kotlin/androidx/camera/camera2/interop/SessionConfigCamera2Interop` include:

- Session parameters (`https://developer.android.com/reference/kotlin/androidx/camera/camera2/interop/SessionConfigurationInterop#sessionParameter()` via `sessionParameter[...]` or `https://developer.android.com/reference/kotlin/androidx/camera/camera2/interop/SessionConfigurationInterop#setSessionParameter(android.hardware.camera2.CaptureRequest.Key,kotlin.Any)`)

- Session type (`https://developer.android.com/reference/kotlin/androidx/camera/camera2/interop/SessionConfigurationInterop#sessionType()`)

- Color space (`https://developer.android.com/reference/kotlin/androidx/camera/camera2/interop/SessionConfigurationInterop#colorSpace()`)

- Session state callbacks (`https://developer.android.com/reference/kotlin/androidx/camera/camera2/interop/SessionConfigurationInterop#setSessionStateCallback(java.util.concurrent.Executor,android.hardware.camera2.CameraCaptureSession.StateCallback)` or `https://developer.android.com/reference/kotlin/androidx/camera/camera2/interop/SessionConfigurationInterop#sessionStateCallback()`)

- Device state callbacks (`https://developer.android.com/reference/kotlin/androidx/camera/camera2/interop/CameraDeviceInterop#setDeviceStateCallback(java.util.concurrent.Executor,android.hardware.camera2.CameraDevice.StateCallback)` or `https://developer.android.com/reference/kotlin/androidx/camera/camera2/interop/CameraDeviceInterop#deviceStateCallback()`)

- Capture request key-value pairs (`https://developer.android.com/reference/kotlin/androidx/camera/camera2/interop/CameraCaptureSessionInterop#captureRequest()` via `captureRequest[...]` or `https://developer.android.com/reference/kotlin/androidx/camera/camera2/interop/CameraCaptureSessionInterop#setCaptureRequestOption(android.hardware.camera2.CaptureRequest.Key,kotlin.Any)`)

- Clearing specific capture request keys (`https://developer.android.com/reference/kotlin/androidx/camera/camera2/interop/CameraCaptureSessionInterop#clearCaptureRequestOption(android.hardware.camera2.CaptureRequest.Key)`)

- Clearing all capture request keys (`https://developer.android.com/reference/kotlin/androidx/camera/camera2/interop/CameraCaptureSessionInterop#clearAllCaptureRequestOptions()`)

- Capture request template type (`https://developer.android.com/reference/kotlin/androidx/camera/camera2/interop/CameraCaptureSessionInterop#repeatingCaptureRequestTemplate()`)

- Repeating capture callbacks (`https://developer.android.com/reference/kotlin/androidx/camera/camera2/interop/CameraCaptureSessionInterop#setRepeatingCaptureCallback(java.util.concurrent.Executor,android.hardware.camera2.CameraCaptureSession.CaptureCallback)` or `https://developer.android.com/reference/kotlin/androidx/camera/camera2/interop/CameraCaptureSessionInterop#repeatingCaptureCallback()`)

**Note:** Using Camera2 interop options can override internal CameraX configurations. If an option configured via interop conflicts with options required by CameraX internally, the option from Camera2Interop will override, which may result in unexpected behavior.

**Warning:** Callbacks configured via interop receive raw `https://developer.android.com/reference/android/hardware/camera2/CameraDevice.html` and `https://developer.android.com/reference/android/hardware/camera2/CameraCaptureSession.html` instances. Directly invoking state-altering, lifecycle, or request-submitting methods on these raw objects bypasses CameraX pipeline management and causes state desynchronization, stream freezing, or crashes. Do not invoke:

- On `https://developer.android.com/reference/android/hardware/camera2/CameraDevice.html`: `https://developer.android.com/reference/android/hardware/camera2/CameraDevice.html#close()` or session creation methods (`https://developer.android.com/reference/android/hardware/camera2/CameraDevice.html#createCaptureSession(android.hardware.camera2.params.SessionConfiguration)`, `https://developer.android.com/reference/android/hardware/camera2/CameraDevice.html#createCaptureSessionByOutputConfigurations(java.util.List&lt;android.hardware.camera2.params.OutputConfiguration&gt;, android.hardware.camera2.CameraCaptureSession.StateCallback, android.os.Handler)`, `https://developer.android.com/reference/android/hardware/camera2/CameraDevice.html#createReprocessableCaptureSession(android.hardware.camera2.params.InputConfiguration, java.util.List&lt;android.view.Surface&gt;, android.hardware.camera2.CameraCaptureSession.StateCallback, android.os.Handler)`, `https://developer.android.com/reference/android/hardware/camera2/CameraDevice.html#createExtensionSession(android.hardware.camera2.params.ExtensionSessionConfiguration)`)

- On `https://developer.android.com/reference/android/hardware/camera2/CameraCaptureSession.html`: lifecycle methods (`https://developer.android.com/reference/android/hardware/camera2/CameraCaptureSession.html#close()`, `https://developer.android.com/reference/android/hardware/camera2/CameraCaptureSession.html#abortCaptures()`, `https://developer.android.com/reference/android/hardware/camera2/CameraCaptureSession.html#stopRepeating()`), request submission methods (`https://developer.android.com/reference/android/hardware/camera2/CameraCaptureSession.html#setRepeatingRequest(android.hardware.camera2.CaptureRequest, android.hardware.camera2.CameraCaptureSession.CaptureCallback, android.os.Handler)`, `https://developer.android.com/reference/android/hardware/camera2/CameraCaptureSession.html#setRepeatingBurst(java.util.List&lt;android.hardware.camera2.CaptureRequest&gt;, android.hardware.camera2.CameraCaptureSession.CaptureCallback, android.os.Handler)`, `https://developer.android.com/reference/android/hardware/camera2/CameraCaptureSession.html#capture(android.hardware.camera2.CaptureRequest, android.hardware.camera2.CameraCaptureSession.CaptureCallback, android.os.Handler)`, `https://developer.android.com/reference/android/hardware/camera2/CameraCaptureSession.html#captureBurst(java.util.List&lt;android.hardware.camera2.CaptureRequest&gt;, android.hardware.camera2.CameraCaptureSession.CaptureCallback, android.os.Handler)`), or surface configuration methods (`https://developer.android.com/reference/android/hardware/camera2/CameraCaptureSession.html#updateOutputConfiguration(android.hardware.camera2.params.OutputConfiguration)`, `https://developer.android.com/reference/android/hardware/camera2/CameraCaptureSession.html#finalizeOutputConfigurations(java.util.List&lt;android.hardware.camera2.params.OutputConfiguration&gt;)`, `https://developer.android.com/reference/android/hardware/camera2/CameraCaptureSession.html#prepare(android.view.Surface)`, `https://developer.android.com/reference/android/hardware/camera2/CameraCaptureSession.html#switchToOffline(java.util.Collection&lt;android.view.Surface&gt;, java.util.concurrent.Executor, android.hardware.camera2.CameraOfflineSession.CameraOfflineSessionCallback)`)

```kotlin
import androidx.camera.camera2.interop.camera2Interop
import androidx.camera.core.SessionConfig
import androidx.camera.core.preview
import androidx.camera.core.sessionConfig

val sessionConfig =
    SessionConfig.Builder(preview)
        .camera2Interop {
            colorSpace = ColorSpace.Named.DISPLAY_P3
            sessionParameter[CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE] = Range(60, 60)
            captureRequest[CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE] = Range(60, 60)
            repeatingCaptureRequestTemplate = CameraDevice.TEMPLATE_PREVIEW
            repeatingCaptureCallback = object : CameraCaptureSession.CaptureCallback() {}
        }
        .build()
```

```kotlin
import androidx.camera.camera2.interop.camera2Interop
import androidx.camera.core.preview
import androidx.camera.core.sessionConfig

val sessionConfig =
    sessionConfig(listOf(preview)) {
        camera2Interop {
            colorSpace = ColorSpace.Named.DISPLAY_P3
            sessionParameter[CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE] = Range(60, 60)
            captureRequest[CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE] = Range(60, 60)
            repeatingCaptureRequestTemplate = CameraDevice.TEMPLATE_PREVIEW
            repeatingCaptureCallback = object : CameraCaptureSession.CaptureCallback() {}
        }
    }
```

| Parameters |
|---|---|
| `crossinline block: https://developer.android.com/reference/kotlin/androidx/camera/camera2/interop/SessionConfigCamera2Interop.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | configuration block setting Camera2 options on `https://developer.android.com/reference/kotlin/androidx/camera/camera2/interop/SessionConfigCamera2Interop` |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig.Builder` | this builder |