CameraInfo


public interface CameraInfo


An interface for retrieving camera information.

Applications can retrieve an instance via getCameraInfo.

Summary

Constants

default static final int

The torch strength level when the device doesn't have a flash unit or doesn't support adjusting torch strength.

Public methods

abstract @NonNull CameraSelector

Returns a CameraSelector unique to this camera.

abstract @NonNull LiveData<CameraState>

Returns a LiveData of the camera's state.

abstract @NonNull ExposureState

Returns a ExposureState.

default @FloatRange(from = 0, fromInclusive = false) float

Returns the intrinsic zoom ratio of this camera.

default int

Returns the lens facing of this camera.

default @NonNull LiveData<Integer>

Returns a LiveData of current LowLightBoostState.

default @IntRange(from = 0) int

Returns the maximum torch strength level.

default @NonNull Set<CameraInfo>

Returns a set of physical camera CameraInfos.

abstract int

Returns the sensor rotation in degrees, relative to the device's "natural" (default) orientation.

abstract int
getSensorRotationDegrees(int relativeRotation)

Returns the sensor rotation, in degrees, relative to the given rotation value.

default @NonNull Set<Range<Integer>>

Returns an unordered set of the frame rate ranges, in frames per second, supported by this device's AE algorithm.

default @NonNull Set<Range<Integer>>

Returns an unordered set of the frame rate ranges, in frames per second, supported by this device's AE algorithm for a specific SessionConfig.

abstract @NonNull LiveData<Integer>

Returns a LiveData of current TorchState.

default @NonNull LiveData<Integer>

Returns the LiveData of the torch strength level.

abstract @NonNull LiveData<ZoomState>

Returns a LiveData of ZoomState.

abstract boolean

Returns if flash unit is available or not.

default boolean

Returns if the GroupableFeature groups set to the provided SessionConfig is supported.

default boolean

Returns if the given FocusMeteringAction is supported on the devices.

default boolean

Returns if logical multi camera is supported on the device.

default boolean

Returns if low-light boost is supported on the device.

default boolean

Returns if configuring torch strength is supported on the device.

default boolean

Returns if CAPTURE_MODE_ZERO_SHUTTER_LAG is supported on the current device.

default static boolean

Returns whether the shutter sound must be played in accordance to regional restrictions.

default @NonNull Set<DynamicRange>
querySupportedDynamicRanges(
    @NonNull Set<DynamicRange> candidateDynamicRanges
)

Returns the supported dynamic ranges of this camera from a set of candidate dynamic ranges.

Constants

TORCH_STRENGTH_LEVEL_UNSUPPORTED

Added in 1.5.0-beta02
default static final int TORCH_STRENGTH_LEVEL_UNSUPPORTED = 0

The torch strength level when the device doesn't have a flash unit or doesn't support adjusting torch strength.

Public methods

getCameraSelector

Added in 1.1.0
abstract @NonNull CameraSelector getCameraSelector()

Returns a CameraSelector unique to this camera.

Returns
@NonNull CameraSelector

CameraSelector unique to this camera.

getCameraState

Added in 1.1.0
abstract @NonNull LiveData<CameraStategetCameraState()

Returns a LiveData of the camera's state.

The LiveData will be updated whenever the camera's state changes, and can be any of the following: PENDING_OPEN, OPENING, OPEN, CLOSING and CLOSED.

Due to the inner workings of LiveData, some reported camera states may be ignored if a newer value is posted before the observers are updated. For instance, this can occur when the camera is opening or closing, the OPENING and CLOSING states may not be reported to observers if they are rapidly followed by the OPEN and CLOSED states respectively.

Returns
@NonNull LiveData<CameraState>

a LiveData of the camera's state.

getExposureState

Added in 1.0.0
abstract @NonNull ExposureState getExposureState()

Returns a ExposureState.

The ExposureState contains the current exposure related information.

getIntrinsicZoomRatio

Added in 1.3.0
default @FloatRange(from = 0, fromInclusive = false) float getIntrinsicZoomRatio()

Returns the intrinsic zoom ratio of this camera.

The intrinsic zoom ratio is defined as the ratio between the angle of view of the default camera and this camera. The default camera is the camera selected by DEFAULT_FRONT_CAMERA or DEFAULT_BACK_CAMERA depending on the lens facing of this camera. For example, if the default camera has angle of view 60 degrees and this camera has 30 degrees, this camera will have intrinsic zoom ratio 2.0.

The intrinsic zoom ratio is calculated approximately based on the focal length and the sensor size. It's considered an inexact attribute of the camera and might not be hundred percent accurate when compared with the output image. Especially for the case that the camera doesn't read the whole sensor area due to cropping being applied.

The default camera is guaranteed to have intrinsic zoom ratio 1.0. Other cameras that have intrinsic zoom ratio greater than 1.0 are considered telephoto cameras and cameras that have intrinsic zoom ratio less than 1.0 are considered ultra wide-angle cameras.

If the camera is unable to provide necessary information to resolve its intrinsic zoom ratio, it will be considered as a standard camera which has intrinsic zoom ratio 1.0.

Returns
@FloatRange(from = 0, fromInclusive = false) float

the intrinsic zoom ratio of this camera.

getLensFacing

Added in 1.3.0
default int getLensFacing()

Returns the lens facing of this camera.

Returns
int

one of LENS_FACING_FRONT and LENS_FACING_BACK, or LENS_FACING_EXTERNAL. If the lens facing of the camera can not be resolved, return LENS_FACING_UNKNOWN.

Throws
java.lang.IllegalArgumentException

If the device cannot return a valid lens facing value, it will throw this exception.

getLowLightBoostState

Added in 1.5.0-beta02
default @NonNull LiveData<IntegergetLowLightBoostState()

Returns a LiveData of current LowLightBoostState.

Low-light boost can be turned on via enableLowLightBoostAsync which will trigger the change event to the returned LiveData. Apps can either get immediate value via getValue or observe it via observe to update low-light boost UI accordingly.

If the camera doesn't support low-light boost, then the state will always be OFF.

Returns
@NonNull LiveData<Integer>

a LiveData containing current low-light boost state.

getMaxTorchStrengthLevel

Added in 1.5.0-beta02
default @IntRange(from = 0) int getMaxTorchStrengthLevel()

Returns the maximum torch strength level.

Returns
@IntRange(from = 0) int

The maximum strength level, or TORCH_STRENGTH_LEVEL_UNSUPPORTED if the device doesn't have a flash unit or doesn't support configuring torch strength.

getPhysicalCameraInfos

Added in 1.4.0
default @NonNull Set<CameraInfogetPhysicalCameraInfos()

Returns a set of physical camera CameraInfos.

A logical camera is a grouping of two or more of those physical cameras. See Multi-camera API

Check isLogicalMultiCameraSupported to see if the device is supporting physical camera or not. If the device doesn't support physical camera, empty set will be returned.

Returns
@NonNull Set<CameraInfo>

Set of physical camera CameraInfos.

getSensorRotationDegrees

Added in 1.0.0
abstract int getSensorRotationDegrees()

Returns the sensor rotation in degrees, relative to the device's "natural" (default) orientation.

See Sensor Coordinate System for more information.

Returns
int

the sensor rotation in degrees, relative to device's "natural" (default) orientation.

getSensorRotationDegrees

Added in 1.0.0
abstract int getSensorRotationDegrees(int relativeRotation)

Returns the sensor rotation, in degrees, relative to the given rotation value.

Valid values for the relative rotation are ROTATION_0 (natural), ROTATION_90, ROTATION_180, ROTATION_270.

Parameters
int relativeRotation

the rotation relative to which the output will be calculated.

Returns
int

the sensor rotation in degrees.

getSupportedFrameRateRanges

Added in 1.3.0
default @NonNull Set<Range<Integer>> getSupportedFrameRateRanges()

Returns an unordered set of the frame rate ranges, in frames per second, supported by this device's AE algorithm.

These are the frame rate ranges that the AE algorithm on the device can support. When CameraX is configured to run with the camera2 implementation, this list will be derived from #CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES, though ranges may be added or removed for compatibility reasons.

There is no guarantee that these ranges can be used for every size surface or combination of use cases. If attempting to run the device using an unsupported range, there may be stability issues or the device may quietly choose another frame rate operating range. The returned set does not have any ordering guarantees. To get the guaranteed supported frame rate ranges under UseCase combination constraints, use getSupportedFrameRateRanges.

Returns
@NonNull Set<Range<Integer>>

The set of FPS ranges supported by the device's AE algorithm

getSupportedFrameRateRanges

Added in 1.5.0-beta02
@ExperimentalSessionConfig
default @NonNull Set<Range<Integer>> getSupportedFrameRateRanges(@NonNull SessionConfig sessionConfig)

Returns an unordered set of the frame rate ranges, in frames per second, supported by this device's AE algorithm for a specific SessionConfig.

These are the frame rate ranges that the AE algorithm on the device can support when a particular SessionConfig is applied. This allows for querying supported frame rates based on the specific configuration of UseCases, which might influence the available ranges.

If the provided SessionConfig has a target frame rate range already set (e.g., set via setTargetFrameRate), this method will ignore that specific setting. The returned set represents all ranges the device can support under the given SessionConfig, irrespective of any pre-defined target frame rate within the config itself.

When CameraX is configured to run with the camera2 implementation, this list will be derived from CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES , though ranges may be added or removed for compatibility reasons or due to constraints imposed by the SessionConfig.

The returned set of frame rate ranges is guaranteed to be supported with the given SessionConfig. An empty set will be returned if the provided SessionConfig is invalid. The returned set does not have any ordering guarantees.

Parameters
@NonNull SessionConfig sessionConfig

The SessionConfig to query supported frame rate ranges for.

Returns
@NonNull Set<Range<Integer>>

The set of FPS ranges supported by the device's AE algorithm for the given session config.

getTorchState

Added in 1.0.0
abstract @NonNull LiveData<IntegergetTorchState()

Returns a LiveData of current TorchState.

The torch can be turned on and off via enableTorch which will trigger the change event to the returned LiveData. Apps can either get immediate value via getValue or observe it via observe to update torch UI accordingly.

If the camera doesn't have a flash unit (see hasFlashUnit), then the torch state will be OFF.

Returns
@NonNull LiveData<Integer>

a LiveData containing current torch state.

getTorchStrengthLevel

Added in 1.5.0-beta02
default @NonNull LiveData<IntegergetTorchStrengthLevel()

Returns the LiveData of the torch strength level.

The value of the LiveData will be the default torch strength level of this device if setTorchStrengthLevel hasn't been called.

The value of the LiveData will be TORCH_STRENGTH_LEVEL_UNSUPPORTED if the device doesn't have a flash unit or doesn't support configuring torch strength.

getZoomState

Added in 1.0.0
abstract @NonNull LiveData<ZoomStategetZoomState()

Returns a LiveData of ZoomState.

The LiveData will be updated whenever the set zoom state has been changed. This can occur when the application updates the zoom via setZoomRatio or setLinearZoom. The zoom state can also change anytime a camera starts up, for example when a UseCase is bound to it.

hasFlashUnit

Added in 1.0.0
abstract boolean hasFlashUnit()

Returns if flash unit is available or not.

isFeatureGroupSupported

Added in 1.5.0-beta02
@ExperimentalSessionConfig
default boolean isFeatureGroupSupported(@NonNull SessionConfig sessionConfig)

Returns if the GroupableFeature groups set to the provided SessionConfig is supported.

This API can be used before calling `bindToLifecycle` API to know if binding a SessionConfig with some given combination of feature groups will work or not.

The following pseudo-code shows an example of how to use this API:

// Disable the unsupported feature options in app feature menu UI once some features have
// already been selected and adding these features will lead to an unsupported configuration.
void disableUnsupportedFeatures(Set<GroupableFeature> selectedFeatures,
        Set<GroupableFeature> appFeatureOptions) {
    for (GroupableFeature featureOption : appFeatureOptions) {
        if (selectedFeatures.contains(featureOption)) { continue; }

        List<GroupableFeature> combinedFeatures = new ArrayList<>(selectedFeatures);
        combinedFeatures.add(featureOption);
        SessionConfig sessionConfig =
            new SessionConfig.Builder(useCases)
                .addRequiredFeatureGroup(combinedFeatures.toArray(new Feature[0]))
                .build();

        if (!cameraInfo.isFeatureGroupSupported(sessionConfig)) {
            disableFeatureOptionInUi