# Camera2CameraControl

Artifact: [androidx.camera:camera-camera2](https://developer.android.com/jetpack/androidx/releases/camera) [View Source](https://cs.android.com/search?q=file:androidx/camera/camera2/interop/Camera2CameraControl.kt+class:androidx.camera.camera2.interop.Camera2CameraControl) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/camera#1.0.0) Deprecated in [1.7.0-rc02](https://developer.android.com/jetpack/androidx/releases/camera#1.7.0-rc02)

*** ** * ** ***


```
@ExperimentalCamera2Interop
public final class Camera2CameraControl
```

<br />

*** ** * ** ***

> [!CAUTION]
> **This class is deprecated.**   
> Use the CameraControl.applyCamera2Interop or CameraControl.applyCamera2InteropAsync extension functions instead, e.g., 'cameraControl.applyCamera2Interop { setCaptureRequestOption(key, value) }'.

A class that provides ability to interoperate with the `https://developer.android.com/reference/android/hardware/camera2/package-summary.html` APIs.

Camera2 specific controls, like capture request options, can be applied through this class. A Camera2CameraControl can be created from a general `https://developer.android.com/reference/androidx/camera/core/CameraControl` which is associated to a camera. Then the controls will affect all use cases that are using that camera.

If any option applied by Camera2CameraControl conflicts with the options required by CameraX internally. The options from Camera2CameraControl will override, which may result in unexpected behavior depends on the options being applied.

Use `https://developer.android.com/reference/androidx/camera/camera2/interop/Camera2Interop#forCameraControl(androidx.core.util.Consumer)` and `https://developer.android.com/reference/androidx/camera/core/CameraControl#applyInteropAsync(androidx.camera.core.InteropConfigurator<? super androidx.camera.core.CameraControl>)` in Java, or `https://developer.android.com/reference/androidx/camera/camera2/interop/package-summary#(androidx.camera.core.CameraControl).applyCamera2Interop(kotlin.Function1)` / `https://developer.android.com/reference/androidx/camera/camera2/interop/package-summary#(androidx.camera.core.CameraControl).applyCamera2InteropAsync(kotlin.Function1)` in Kotlin instead.

## Summary

| ### Public methods |
|---|---|
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://developer.android.com/reference/java/lang/Void.html>` | `[addCaptureRequestOptions](https://developer.android.com/reference/androidx/camera/camera2/interop/Camera2CameraControl#addCaptureRequestOptions(androidx.camera.camera2.interop.CaptureRequestOptions))(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/camera2/interop/CaptureRequestOptions bundle)` **This method is deprecated.** Use the CameraControl.applyCamera2Interop or CameraControl.applyCamera2InteropAsync extension functions instead, e.g., 'cameraControl.applyCamera2Interop { setCaptureRequestOption(key, value) }'. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://developer.android.com/reference/java/lang/Void.html>` | `[clearCaptureRequestOptions](https://developer.android.com/reference/androidx/camera/camera2/interop/Camera2CameraControl#clearCaptureRequestOptions())()` **This method is deprecated.** Use the CameraControl.applyCamera2Interop or CameraControl.applyCamera2InteropAsync extension functions instead, e.g., 'cameraControl.applyCamera2Interop { setCaptureRequestOption(key, value) }'. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/camera2/interop/Camera2CameraControl` | `[from](https://developer.android.com/reference/androidx/camera/camera2/interop/Camera2CameraControl#from(androidx.camera.core.CameraControl))(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/core/CameraControl cameraControl)` **This method is deprecated.** Use the CameraControl.applyCamera2Interop or CameraControl.applyCamera2InteropAsync extension functions instead, e.g., 'cameraControl.applyCamera2Interop { setCaptureRequestOption(key, value) }'. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/camera2/interop/CaptureRequestOptions` | `[getCaptureRequestOptions](https://developer.android.com/reference/androidx/camera/camera2/interop/Camera2CameraControl#getCaptureRequestOptions())()` **This method is deprecated.** Use the CameraControl.applyCamera2Interop or CameraControl.applyCamera2InteropAsync extension functions instead, e.g., 'cameraControl.applyCamera2Interop { setCaptureRequestOption(key, value) }'. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://developer.android.com/reference/java/lang/Void.html>` | `[setCaptureRequestOptions](https://developer.android.com/reference/androidx/camera/camera2/interop/Camera2CameraControl#setCaptureRequestOptions(androidx.camera.camera2.interop.CaptureRequestOptions))(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/camera2/interop/CaptureRequestOptions bundle)` **This method is deprecated.** Use the CameraControl.applyCamera2Interop or CameraControl.applyCamera2InteropAsync extension functions instead, e.g., 'cameraControl.applyCamera2Interop { setCaptureRequestOption(key, value) }'. |

## Public methods

### addCaptureRequestOptions

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

```
public final @NonNull ListenableFuture<Void> [addCaptureRequestOptions](https://developer.android.com/reference/androidx/camera/camera2/interop/Camera2CameraControl#addCaptureRequestOptions(androidx.camera.camera2.interop.CaptureRequestOptions))(@NonNull CaptureRequestOptions bundle)
```

> [!CAUTION]
> **This method is deprecated.**   
> Use the CameraControl.applyCamera2Interop or CameraControl.applyCamera2InteropAsync extension functions instead, e.g., 'cameraControl.applyCamera2Interop { setCaptureRequestOption(key, value) }'.

Adds a `https://developer.android.com/reference/androidx/camera/camera2/interop/CaptureRequestOptions` updates the session with the options it contains.

The options will be merged with the existing options. If one option is set with a different value, it will overwrite the existing value.

Any values which are in conflict with values already set by CameraX, such as by `https://developer.android.com/reference/androidx/camera/core/CameraControl`, will overwrite the existing values. The values will be submitted with every repeating and single capture requests issued by CameraX, which may result in unexpected behavior depends on the values being applied.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/camera2/interop/CaptureRequestOptions bundle` | The `https://developer.android.com/reference/androidx/camera/camera2/interop/CaptureRequestOptions` which will be set. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://developer.android.com/reference/java/lang/Void.html>` | a `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html` which completes when the repeating `https://developer.android.com/reference/android/hardware/camera2/CaptureResult.html` shows the options have be submitted completely. The future fails with `https://developer.android.com/reference/androidx/camera/core/CameraControl.OperationCanceledException` if newer options are set or camera is closed before the current request completes. |

### clearCaptureRequestOptions

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/camera#1.1.0) Deprecated in [1.7.0-rc02](https://developer.android.com/jetpack/androidx/releases/camera#1.7.0-rc02)

```
public final @NonNull ListenableFuture<Void> [clearCaptureRequestOptions](https://developer.android.com/reference/androidx/camera/camera2/interop/Camera2CameraControl#clearCaptureRequestOptions())()
```

> [!CAUTION]
> **This method is deprecated.**   
> Use the CameraControl.applyCamera2Interop or CameraControl.applyCamera2InteropAsync extension functions instead, e.g., 'cameraControl.applyCamera2Interop { setCaptureRequestOption(key, value) }'.

Clears all capture request options that is currently applied by the `https://developer.android.com/reference/androidx/camera/camera2/interop/Camera2CameraControl`.

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://developer.android.com/reference/java/lang/Void.html>` | a `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html` which completes when the repeating `https://developer.android.com/reference/android/hardware/camera2/CaptureResult.html` shows the options have be submitted completely. The future fails with `https://developer.android.com/reference/androidx/camera/core/CameraControl.OperationCanceledException` if newer options are set or camera is closed before the current request completes. |

### from

Added in [1.6.0](https://developer.android.com/jetpack/androidx/releases/camera#1.6.0) Deprecated in [1.7.0-rc02](https://developer.android.com/jetpack/androidx/releases/camera#1.7.0-rc02)

```
public static final @NonNull Camera2CameraControl [from](https://developer.android.com/reference/androidx/camera/camera2/interop/Camera2CameraControl#from(androidx.camera.core.CameraControl))(@NonNull CameraControl cameraControl)
```

> [!CAUTION]
> **This method is deprecated.**   
> Use the CameraControl.applyCamera2Interop or CameraControl.applyCamera2InteropAsync extension functions instead, e.g., 'cameraControl.applyCamera2Interop { setCaptureRequestOption(key, value) }'.

Gets the `https://developer.android.com/reference/androidx/camera/camera2/interop/Camera2CameraControl` from a `https://developer.android.com/reference/androidx/camera/core/CameraControl`.

The `https://developer.android.com/reference/androidx/camera/core/CameraControl` is still usable after a `https://developer.android.com/reference/androidx/camera/camera2/interop/Camera2CameraControl` is obtained from it. Note that the `https://developer.android.com/reference/androidx/camera/camera2/interop/Camera2CameraControl` has higher priority than the `https://developer.android.com/reference/androidx/camera/core/CameraControl`. For example, if `https://developer.android.com/reference/android/hardware/camera2/CaptureRequest.html#FLASH_MODE` is set through the `https://developer.android.com/reference/androidx/camera/camera2/interop/Camera2CameraControl`. All `https://developer.android.com/reference/androidx/camera/core/CameraControl` features that required `https://developer.android.com/reference/android/hardware/camera2/CaptureRequest.html#FLASH_MODE` internally like torch may not work properly.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/core/CameraControl cameraControl` | The `https://developer.android.com/reference/androidx/camera/core/CameraControl` to get from. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/camera2/interop/Camera2CameraControl` | The camera control with Camera2 implementation. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | if the camera control does not contain the camera2 information (e.g., if CameraX was not initialized with a `https://developer.android.com/reference/androidx/camera/camera2/Camera2Config`). |

### getCaptureRequestOptions

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

```
public final @NonNull CaptureRequestOptions [getCaptureRequestOptions](https://developer.android.com/reference/androidx/camera/camera2/interop/Camera2CameraControl#getCaptureRequestOptions())()
```

> [!CAUTION]
> **This method is deprecated.**   
> Use the CameraControl.applyCamera2Interop or CameraControl.applyCamera2InteropAsync extension functions instead, e.g., 'cameraControl.applyCamera2Interop { setCaptureRequestOption(key, value) }'.

Gets all the capture request options that is currently applied by the `https://developer.android.com/reference/androidx/camera/camera2/interop/Camera2CameraControl`.

It doesn't include the capture request options applied by the `https://developer.android.com/reference/android/hardware/camera2/CameraDevice.html` templates or by CameraX.

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/camera2/interop/CaptureRequestOptions` | The `https://developer.android.com/reference/androidx/camera/camera2/interop/CaptureRequestOptions`. |

### setCaptureRequestOptions

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

```
public final @NonNull ListenableFuture<Void> [setCaptureRequestOptions](https://developer.android.com/reference/androidx/camera/camera2/interop/Camera2CameraControl#setCaptureRequestOptions(androidx.camera.camera2.interop.CaptureRequestOptions))(@NonNull CaptureRequestOptions bundle)
```

> [!CAUTION]
> **This method is deprecated.**   
> Use the CameraControl.applyCamera2Interop or CameraControl.applyCamera2InteropAsync extension functions instead, e.g., 'cameraControl.applyCamera2Interop { setCaptureRequestOption(key, value) }'.

Sets a `https://developer.android.com/reference/androidx/camera/camera2/interop/CaptureRequestOptions` and updates the session with the options it contains.

This will first clear all options that have already been set, then apply the new options.

Any values which are in conflict with values already set by CameraX, such as by `https://developer.android.com/reference/androidx/camera/core/CameraControl`, will overwrite the existing values. The values will be submitted with every repeating and single capture requests issued by CameraX, which may result in unexpected behavior depending on the values being applied.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/camera2/interop/CaptureRequestOptions bundle` | The `https://developer.android.com/reference/androidx/camera/camera2/interop/CaptureRequestOptions` which will be set. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://developer.android.com/reference/java/lang/Void.html>` | a `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html` which completes when the repeating `https://developer.android.com/reference/android/hardware/camera2/CaptureResult.html` shows the options have be submitted completely. The future fails with `https://developer.android.com/reference/androidx/camera/core/CameraControl.OperationCanceledException` if newer options are set or camera is closed before the current request completes. Cancelling the ListenableFuture is a no-op. |