# 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)

*** ** * ** ***


```
public final class CameraXConfig.Builder
```

<br />

*** ** * ** ***

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

## Summary

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

## Public methods

### build

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

```
public @NonNull CameraXConfig build()
```

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

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/core/CameraXConfig` | A `https://developer.android.com/reference/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)

```
public static @NonNull CameraXConfig.Builder fromConfig(@NonNull CameraXConfig configuration)
```

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

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/core/CameraXConfig configuration` | An immutable configuration to pre-populate this builder. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/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)

```
public @NonNull CameraXConfig.Builder setAvailableCamerasLimiter(
    @NonNull CameraSelector availableCameraSelector
)
```

Sets a `https://developer.android.com/reference/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/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)

```
public @NonNull CameraXConfig.Builder setCameraExecutor(@NonNull Executor executor)
```

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)

```
public @NonNull CameraXConfig.Builder setCameraOpenRetryMaxTimeoutInMillisWhileResuming(
    long maxTimeoutInMillis
)
```

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/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 |
|---|---|
| `long maxTimeoutInMillis` | The max timeout in milliseconds. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/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
public @NonNull CameraXConfig.Builder setCameraProviderInitRetryPolicy(@NonNull RetryPolicy retryPolicy)
```

Sets the `https://developer.android.com/reference/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/androidx/camera/core/RetryPolicy#DEFAULT()` will be applied.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/core/RetryPolicy retryPolicy` | The `https://developer.android.com/reference/androidx/camera/core/RetryPolicy` to use for retrying the CameraProvider initialization. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/core/CameraXConfig.Builder` | this builder. |

### setMinimumLoggingLevel

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

```
public @NonNull CameraXConfig.Builder setMinimumLoggingLevel(
    @IntRange(from = Log.DEBUG, to = Log.ERROR) int logLevel
)
```

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 |
|---|---|
| `@https://developer.android.com/reference/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) int logLevel` | 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://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/core/CameraXConfig.Builder` | This `https://developer.android.com/reference/androidx/camera/core/CameraXConfig.Builder` instance. |

### setSchedulerHandler

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

```
public @NonNull CameraXConfig.Builder setSchedulerHandler(@NonNull Handler handler)
```

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/androidx/camera/core/CameraXConfig.Builder#setCameraExecutor(java.util.concurrent.Executor)` |   |