public final class

CameraXConfig.Builder

extends java.lang.Object

implements TargetConfig.Builder<CameraX, CameraXConfig.Builder>

 java.lang.Object

↳androidx.camera.core.CameraXConfig.Builder

Overview

A builder for generating CameraXConfig objects.

Summary

Constructors
publicBuilder()

Creates a new Builder object.

Methods
public CameraXConfigbuild()

Builds an immutable CameraXConfig from the current state.

public static CameraXConfig.BuilderfromConfig(CameraXConfig configuration)

Generates a Builder from another CameraXConfig object

public CameraXConfig.BuildersetAvailableCamerasLimiter(CameraSelector availableCameraSelector)

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

public CameraXConfig.BuildersetCameraExecutor(java.util.concurrent.Executor executor)

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

public CameraXConfig.BuildersetCameraFactoryProvider(CameraFactory.Provider cameraFactory)

Sets the CameraFactory implementation for the application.

public CameraXConfig.BuildersetCameraOpenRetryMaxTimeoutInMillisWhileResuming(long maxTimeoutInMillis)

Sets the camera open retry maximum timeout in milliseconds.

public CameraXConfig.BuildersetCameraProviderInitRetryPolicy(RetryPolicy retryPolicy)

Sets the RetryPolicy for the CameraProvider initialization.

public CameraXConfig.BuildersetDeviceSurfaceManagerProvider(CameraDeviceSurfaceManager.Provider surfaceManagerProvider)

Sets the CameraDeviceSurfaceManager implementation for the application.

public CameraXConfig.BuildersetMinimumLoggingLevel(int logLevel)

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

public CameraXConfig.BuildersetQuirkSettings(QuirkSettings quirkSettings)

Sets the quirk settings.

public CameraXConfig.BuildersetSchedulerHandler(Handler handler)

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

public CameraXConfig.BuildersetTargetClass(java.lang.Class<CameraX> targetClass)

public CameraXConfig.BuildersetTargetName(java.lang.String targetName)

public CameraXConfig.BuildersetUseCaseConfigFactoryProvider(UseCaseConfigFactory.Provider configFactoryProvider)

Sets the UseCaseConfigFactory implementation for the application.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public Builder()

Creates a new Builder object.

Methods

public static CameraXConfig.Builder fromConfig(CameraXConfig configuration)

Generates a Builder from another CameraXConfig object

Parameters:

configuration: An immutable configuration to pre-populate this builder.

Returns:

The new Builder.

public CameraXConfig.Builder setCameraFactoryProvider(CameraFactory.Provider cameraFactory)

Sets the CameraFactory implementation for the application.

public CameraXConfig.Builder setDeviceSurfaceManagerProvider(CameraDeviceSurfaceManager.Provider surfaceManagerProvider)

Sets the CameraDeviceSurfaceManager implementation for the application.

public CameraXConfig.Builder setUseCaseConfigFactoryProvider(UseCaseConfigFactory.Provider configFactoryProvider)

Sets the UseCaseConfigFactory implementation for the application.

This factory should produce all default configurations for the application's use cases.

public CameraXConfig.Builder setCameraExecutor(java.util.concurrent.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.

public CameraXConfig.Builder setSchedulerHandler(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.

See also: CameraXConfig.Builder.setCameraExecutor(Executor)

public CameraXConfig.Builder setMinimumLoggingLevel(int logLevel)

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

The logging level should be one of the following: , , or .

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

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

Parameters:

logLevel: The minimum logging level, which should be , , or .

Returns:

This CameraXConfig.Builder instance.

public CameraXConfig.Builder setAvailableCamerasLimiter(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 java.lang.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 CameraSelector.DEFAULT_BACK_CAMERA and then CameraX will avoid initializing front facing cameras to reduce the latency.

public 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 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: The max timeout in milliseconds.

Returns:

this builder.

public CameraXConfig.Builder setCameraProviderInitRetryPolicy(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 RetryPolicy.DEFAULT will be applied.

Parameters:

retryPolicy: The RetryPolicy to use for retrying the CameraProvider initialization.

Returns:

this builder.

public CameraXConfig.Builder setQuirkSettings(QuirkSettings quirkSettings)

Sets the quirk settings.

Parameters:

quirkSettings: the quirk settings.

Returns:

this builder.

public CameraXConfig build()

Builds an immutable CameraXConfig from the current state.

Returns:

A CameraXConfig populated with the current state.

public CameraXConfig.Builder setTargetClass(java.lang.Class<CameraX> targetClass)

public CameraXConfig.Builder setTargetName(java.lang.String targetName)