# CameraXConfig.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/CameraXConfig.java+class:androidx.camera.core.CameraXConfig.Builder) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/camera#1.0.0)

*** ** * ** ***


```
class CameraXConfig.Builder
```

<br />

*** ** * ** ***

A builder for generating `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraXConfig` objects.

## Summary

| ### Public functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraXConfig` | `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraXConfig.Builder#build()()` Builds an immutable `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraXConfig` from the current state. |
| `java-static https://developer.android.com/reference/kotlin/androidx/camera/core/CameraXConfig.Builder` | `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraXConfig.Builder#fromConfig(androidx.camera.core.CameraXConfig)(configuration: https://developer.android.com/reference/kotlin/androidx/camera/core/CameraXConfig)` Generates a Builder from another `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraXConfig` object |
| `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraXConfig.Builder` | `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraXConfig.Builder#setAvailableCamerasLimiter(androidx.camera.core.CameraSelector)(availableCameraSelector: https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector)` Sets a `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector` to determine the available cameras, thus defining which cameras can be used in the application. |
| `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraXConfig.Builder` | `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraXConfig.Builder#setCameraExecutor(java.util.concurrent.Executor)(executor: https://developer.android.com/reference/java/util/concurrent/Executor.html)` Sets an executor which CameraX will use to drive the camera stack. |
| `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraXConfig.Builder` | `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraXConfig.Builder#setCameraOpenRetryMaxTimeoutInMillisWhileResuming(long)( maxTimeoutInMillis: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html )` Sets the camera open retry maximum timeout in milliseconds. |
| `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraXConfig.Builder` | `@https://developer.android.com/reference/kotlin/androidx/camera/core/ExperimentalRetryPolicy https://developer.android.com/reference/kotlin/androidx/camera/core/CameraXConfig.Builder#setCameraProviderInitRetryPolicy(androidx.camera.core.RetryPolicy)(retryPolicy: https://developer.android.com/reference/kotlin/androidx/camera/core/RetryPolicy)` Sets the `https://developer.android.com/reference/kotlin/androidx/camera/core/RetryPolicy` for the CameraProvider initialization. |
| `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraXConfig.Builder` | `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraXConfig.Builder#setMinimumLoggingLevel(int)( logLevel: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = https://developer.android.com/reference/android/util/Log.html#DEBUG, to = https://developer.android.com/reference/android/util/Log.html#ERROR) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html )` Sets the minimum logging level to be used for CameraX logs. |
| `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraXConfig.Builder` | `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraXConfig.Builder#setSchedulerHandler(android.os.Handler)(handler: https://developer.android.com/reference/android/os/Handler.html)` Sets a handler that CameraX will use internally for scheduling future tasks. |

## Public functions

### build

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

```
fun build(): CameraXConfig
```

Builds an immutable `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraXConfig` from the current state.

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraXConfig` | A `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraXConfig` populated with the current state. |

### fromConfig

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

```
java-static fun fromConfig(configuration: CameraXConfig): CameraXConfig.Builder
```

Generates a Builder from another `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraXConfig` object

| Parameters |
|---|---|
| `configuration: https://developer.android.com/reference/kotlin/androidx/camera/core/CameraXConfig` | An immutable configuration to pre-populate this builder. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraXConfig.Builder` | The new Builder. |

### setAvailableCamerasLimiter

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

```
fun setAvailableCamerasLimiter(availableCameraSelector: CameraSelector): CameraXConfig.Builder
```

Sets a `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector` to determine the available cameras, thus defining which cameras can be used in the application.

Only cameras selected by this CameraSelector can be used in the application. If the application binds use cases with a CameraSelector that selects an unavailable camera, an `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` will be thrown.

This configuration can help CameraX optimize the latency of CameraX initialization. The tasks CameraX initialization performs include enumerating cameras, querying camera characteristics and retrieving properties in preparation for resolution determination. On some low end devices, these tasks could take a significant amount of time. Using this method can avoid the initialization of unnecessary cameras and speed up the time for camera start-up. For example, if the application uses only back facing cameras, it can set this configuration with `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector#DEFAULT_BACK_CAMERA()` and then CameraX will avoid initializing front facing cameras to reduce the latency.

### setCameraExecutor

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

```
fun setCameraExecutor(executor: Executor): CameraXConfig.Builder
```

Sets an executor which CameraX will use to drive the camera stack.

This option can be used to override the default internal executor created by CameraX, and will be used by the implementation to drive all cameras.

It is not necessary to set an executor for normal use, and should only be used in applications with very specific threading requirements. If not set, CameraX will create and use an optimized default internal executor.

### setCameraOpenRetryMaxTimeoutInMillisWhileResuming

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

```
fun setCameraOpenRetryMaxTimeoutInMillisWhileResuming(
    maxTimeoutInMillis: Long
): CameraXConfig.Builder
```

Sets the camera open retry maximum timeout in milliseconds. This is only needed when users don't want to retry camera opening for a long time.

When `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner` is in ON_RESUME state, CameraX will actively retry opening the camera periodically to resume, until there is non-recoverable errors happening and then move to pending open state waiting for the next camera available after timeout.

When in active resuming mode, it will periodically retry opening the camera regardless of the camera availability. Elapsed time \<= 2 minutes -\> retry once per 1 second. Elapsed time 2 to 5 minutes -\> retry once per 2 seconds. Elapsed time \>5 minutes -\> retry once per 4 seconds. Retry will stop after 30 minutes.

When not in active resuming mode, the camera will be attempted to be opened every 700ms for 10 seconds. This value cannot currently be changed.

| Parameters |
|---|---|
| `maxTimeoutInMillis: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | The max timeout in milliseconds. |

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

### setCameraProviderInitRetryPolicy

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

```
@ExperimentalRetryPolicy
fun setCameraProviderInitRetryPolicy(retryPolicy: RetryPolicy): CameraXConfig.Builder
```

Sets the `https://developer.android.com/reference/kotlin/androidx/camera/core/RetryPolicy` for the CameraProvider initialization. This policy determines whether to retry the CameraProvider initialization if it fails.

If not set, a default retry policy `https://developer.android.com/reference/kotlin/androidx/camera/core/RetryPolicy#DEFAULT()` will be applied.

| Parameters |
|---|---|
| `retryPolicy: https://developer.android.com/reference/kotlin/androidx/camera/core/RetryPolicy` | The `https://developer.android.com/reference/kotlin/androidx/camera/core/RetryPolicy` to use for retrying the CameraProvider initialization. |

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

### setMinimumLoggingLevel

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

```
fun setMinimumLoggingLevel(
    logLevel: @IntRange(from = Log.DEBUG, to = Log.ERROR) Int
): CameraXConfig.Builder
```

Sets the minimum logging level to be used for CameraX logs.

The logging level should be one of the following: `https://developer.android.com/reference/android/util/Log.html#DEBUG`, `https://developer.android.com/reference/android/util/Log.html#INFO`, `https://developer.android.com/reference/android/util/Log.html#WARN` or `https://developer.android.com/reference/android/util/Log.html#ERROR`.

When not specified, the default minimum logging level used inside CameraX is `https://developer.android.com/reference/android/util/Log.html#DEBUG`.

For apps that want to reduce the logs produced by CameraX, set it to `https://developer.android.com/reference/android/util/Log.html#ERROR` to avoid all logs except for error.

| Parameters |
|---|---|
| `logLevel: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = https://developer.android.com/reference/android/util/Log.html#DEBUG, to = https://developer.android.com/reference/android/util/Log.html#ERROR) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The minimum logging level, which should be `https://developer.android.com/reference/android/util/Log.html#DEBUG`, `https://developer.android.com/reference/android/util/Log.html#INFO`, `https://developer.android.com/reference/android/util/Log.html#WARN` or `https://developer.android.com/reference/android/util/Log.html#ERROR`. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraXConfig.Builder` | This `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraXConfig.Builder` instance. |

### setSchedulerHandler

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

```
fun setSchedulerHandler(handler: Handler): CameraXConfig.Builder
```

Sets a handler that CameraX will use internally for scheduling future tasks.

This scheduler may also be used for legacy APIs which require a `https://developer.android.com/reference/android/os/Handler.html`. Tasks that are scheduled with this handler will always be executed by the camera executor. No business logic will be executed directly by this handler.

It is not necessary to set a scheduler handler for normal use, and should only be used in applications with very specific threading requirements. If not set, CameraX will create and use an optimized default internal handler.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraXConfig.Builder#setCameraExecutor(java.util.concurrent.Executor)` |   |