CameraXConfig.Builder


public final class CameraXConfig.Builder


A builder for generating CameraXConfig objects.

Summary

Public methods

@NonNull CameraXConfig

Builds an immutable CameraXConfig from the current state.

static @NonNull CameraXConfig.Builder

Generates a Builder from another CameraXConfig object

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

Sets a CameraSelector to determine the available cameras, thus defining which cameras can be used in the application.

@NonNull CameraXConfig.Builder

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

@NonNull CameraXConfig.Builder
setCameraOpenRetryMaxTimeoutInMillisWhileResuming(
    long maxTimeoutInMillis
)

Sets the camera open retry maximum timeout in milliseconds.

@NonNull CameraXConfig.Builder

Sets the RetryPolicy for the CameraProvider initialization.

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

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

@NonNull CameraXConfig.Builder

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

Public methods

build

Added in 1.0.0
public @NonNull CameraXConfig build()

Builds an immutable CameraXConfig from the current state.

Returns
@NonNull CameraXConfig

A CameraXConfig populated with the current state.

fromConfig

Added in 1.0.0
public static @NonNull CameraXConfig.Builder fromConfig(@NonNull CameraXConfig configuration)

Generates a Builder from another CameraXConfig object

Parameters
@NonNull CameraXConfig configuration

An immutable configuration to pre-populate this builder.

Returns
@NonNull CameraXConfig.Builder

The new Builder.

setAvailableCamerasLimiter

Added in 1.1.0
public @NonNull CameraXConfig.Builder setAvailableCamerasLimiter(
    @NonNull CameraSelector availableCameraSelector
)

Sets a 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 IllegalArgumentException 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 DEFAULT_BACK_CAMERA and then CameraX will avoid initializing front facing cameras to reduce the latency.

setCameraExecutor

Added in 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
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 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
@NonNull CameraXConfig.Builder

this builder.

setCameraProviderInitRetryPolicy

Added in 1.4.0
@ExperimentalRetryPolicy
public @NonNull CameraXConfig.Builder setCameraProviderInitRetryPolicy(@NonNull RetryPolicy retryPolicy)

Sets the RetryPolicy for the CameraProvider initialization. This policy determines whether to retry the CameraProvider initialization if it fails.

If not set, a default retry policy DEFAULT will be applied.

Parameters
@NonNull RetryPolicy retryPolicy

The RetryPolicy to use for retrying the CameraProvider initialization.

Returns
@NonNull CameraXConfig.Builder

this builder.

setMinimumLoggingLevel

Added in 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: DEBUG, INFO, WARN or ERROR.

When not specified, the default minimum logging level used inside CameraX is DEBUG.

For apps that want to reduce the logs produced by CameraX, set it to ERROR to avoid all logs except for error.

Parameters
@IntRange(from = Log.DEBUG, to = Log.ERROR) int logLevel

The minimum logging level, which should be DEBUG, INFO, WARN or ERROR.

Returns
@NonNull CameraXConfig.Builder

This Builder instance.

setSchedulerHandler

Added in 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 Handler. 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.