CameraXConfig.Builder


class CameraXConfig.Builder


A builder for generating CameraXConfig objects.

Summary

Public functions

CameraXConfig

Builds an immutable CameraXConfig from the current state.

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

Generates a Builder from another CameraXConfig object

CameraXConfig.Builder
setAvailableCamerasLimiter(availableCameraSelector: CameraSelector)

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

CameraXConfig.Builder

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

CameraXConfig.Builder

Sets the camera open retry maximum timeout in milliseconds.

CameraXConfig.Builder

Sets the RetryPolicy for the CameraProvider initialization.

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

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

CameraXConfig.Builder

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

Public functions

build

Added in 1.0.0
fun build(): CameraXConfig

Builds an immutable CameraXConfig from the current state.

Returns
CameraXConfig

A CameraXConfig populated with the current state.

fromConfig

Added in 1.0.0
java-static fun fromConfig(configuration: CameraXConfig): CameraXConfig.Builder

Generates a Builder from another CameraXConfig object

Parameters
configuration: CameraXConfig

An immutable configuration to pre-populate this builder.

Returns
CameraXConfig.Builder

The new Builder.

setAvailableCamerasLimiter

Added in 1.1.0
fun setAvailableCamerasLimiter(availableCameraSelector: CameraSelector): CameraXConfig.Builder

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
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
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 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: Long

The max timeout in milliseconds.

Returns
CameraXConfig.Builder

this builder.

setCameraProviderInitRetryPolicy

Added in 1.4.0
@ExperimentalRetryPolicy
fun setCameraProviderInitRetryPolicy(retryPolicy: RetryPolicy): CameraXConfig.Builder

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
retryPolicy: RetryPolicy

The RetryPolicy to use for retrying the CameraProvider initialization.

Returns
CameraXConfig.Builder

this builder.

setMinimumLoggingLevel

Added in 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: 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
logLevel: @IntRange(from = Log.DEBUG, to = Log.ERROR) Int

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

Returns
CameraXConfig.Builder

This Builder instance.

setSchedulerHandler

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