# Camera2Interop.Extender

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/Camera2Interop.kt+class:androidx.camera.camera2.interop.Camera2Interop.Extender) 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
class Camera2Interop.Extender<T : Any?>
```

<br />

*** ** * ** ***

> [!CAUTION]
> **This class is deprecated.**   
> Use the camera2Interop extension function on UseCase.Builder (e.g., 'builder.camera2Interop { setPhysicalCameraId(physicalCameraId) }') or SessionConfig.Builder for capture request options and callbacks instead.

Extends `https://developer.android.com/reference/kotlin/androidx/camera/camera2/interop/Camera2Interop.Extender#(androidx.camera.core.ExtendableBuilder)` to add Camera2 options.

Use `https://developer.android.com/reference/kotlin/androidx/camera/camera2/interop/Camera2Interop#forUseCase(androidx.core.util.Consumer)`, `https://developer.android.com/reference/kotlin/androidx/camera/camera2/interop/Camera2Interop#forImageCapture(androidx.core.util.Consumer)`, or `https://developer.android.com/reference/kotlin/androidx/camera/camera2/interop/Camera2Interop#forSessionConfig(androidx.core.util.Consumer)` in Java, or the `camera2Interop` extension function in Kotlin instead (e.g. `UseCase.Builder.camera2Interop` for physical camera ID or `SessionConfig.Builder.camera2Interop` for capture request options and callbacks).

| Parameters |
|---|---|
| `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?>` | the type being built by the extendable builder. |

## Summary

| ### Public constructors |
|---|
| `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> [Extender](https://developer.android.com/reference/kotlin/androidx/camera/camera2/interop/Camera2Interop.Extender#Extender(androidx.camera.core.ExtendableBuilder))(baseBuilder: https://developer.android.com/reference/kotlin/androidx/camera/core/ExtendableBuilder<T>)` **This function is deprecated.** Use the camera2Interop extension function on UseCase.Builder (e.g., 'builder.camera2Interop { setPhysicalCameraId(physicalCameraId) }') or SessionConfig.Builder for capture request options and callbacks instead. |

| ### Public functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/camera2/interop/Camera2Interop.Extender<T>` | `<ValueT : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> [setCaptureRequestOption](https://developer.android.com/reference/kotlin/androidx/camera/camera2/interop/Camera2Interop.Extender#setCaptureRequestOption(android.hardware.camera2.CaptureRequest.Key,kotlin.Any))( key: https://developer.android.com/reference/android/hardware/camera2/CaptureRequest.Key.html<ValueT>, value: ValueT )` **This function is deprecated.** Use the camera2Interop extension function on UseCase.Builder (e.g., 'builder.camera2Interop { setPhysicalCameraId(physicalCameraId) }') or SessionConfig.Builder for capture request options and callbacks instead. |
| `https://developer.android.com/reference/kotlin/androidx/camera/camera2/interop/Camera2Interop.Extender<T>` | `[setDeviceStateCallback](https://developer.android.com/reference/kotlin/androidx/camera/camera2/interop/Camera2Interop.Extender#setDeviceStateCallback(android.hardware.camera2.CameraDevice.StateCallback))(stateCallback: https://developer.android.com/reference/android/hardware/camera2/CameraDevice.StateCallback.html)` **This function is deprecated.** Use the camera2Interop extension function on UseCase.Builder (e.g., 'builder.camera2Interop { setPhysicalCameraId(physicalCameraId) }') or SessionConfig.Builder for capture request options and callbacks instead. |
| `https://developer.android.com/reference/kotlin/androidx/camera/camera2/interop/Camera2Interop.Extender<T>` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 28) [setPhysicalCameraId](https://developer.android.com/reference/kotlin/androidx/camera/camera2/interop/Camera2Interop.Extender#setPhysicalCameraId(kotlin.String))(cameraId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` **This function is deprecated.** Use the camera2Interop extension function on UseCase.Builder (e.g., 'builder.camera2Interop { setPhysicalCameraId(physicalCameraId) }') or SessionConfig.Builder for capture request options and callbacks instead. |
| `https://developer.android.com/reference/kotlin/androidx/camera/camera2/interop/Camera2Interop.Extender<T>` | `[setSessionCaptureCallback](https://developer.android.com/reference/kotlin/androidx/camera/camera2/interop/Camera2Interop.Extender#setSessionCaptureCallback(android.hardware.camera2.CameraCaptureSession.CaptureCallback))( captureCallback: https://developer.android.com/reference/android/hardware/camera2/CameraCaptureSession.CaptureCallback.html )` **This function is deprecated.** Use the camera2Interop extension function on UseCase.Builder (e.g., 'builder.camera2Interop { setPhysicalCameraId(physicalCameraId) }') or SessionConfig.Builder for capture request options and callbacks instead. |
| `https://developer.android.com/reference/kotlin/androidx/camera/camera2/interop/Camera2Interop.Extender<T>` | `[setSessionStateCallback](https://developer.android.com/reference/kotlin/androidx/camera/camera2/interop/Camera2Interop.Extender#setSessionStateCallback(android.hardware.camera2.CameraCaptureSession.StateCallback))( stateCallback: https://developer.android.com/reference/android/hardware/camera2/CameraCaptureSession.StateCallback.html )` **This function is deprecated.** Use the camera2Interop extension function on UseCase.Builder (e.g., 'builder.camera2Interop { setPhysicalCameraId(physicalCameraId) }') or SessionConfig.Builder for capture request options and callbacks instead. |
| `https://developer.android.com/reference/kotlin/androidx/camera/camera2/interop/Camera2Interop.Extender<T>` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 33) [setStreamUseCase](https://developer.android.com/reference/kotlin/androidx/camera/camera2/interop/Camera2Interop.Extender#setStreamUseCase(kotlin.Long))(streamUseCase: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)` **This function is deprecated.** Use the camera2Interop extension function on UseCase.Builder (e.g., 'builder.camera2Interop { setPhysicalCameraId(physicalCameraId) }') or SessionConfig.Builder for capture request options and callbacks instead. |

## Public constructors

### Extender

```
<T : Any?> [Extender](https://developer.android.com/reference/kotlin/androidx/camera/camera2/interop/Camera2Interop.Extender#Extender(androidx.camera.core.ExtendableBuilder))(baseBuilder: ExtendableBuilder<T>)
```

> [!CAUTION]
> **This function is deprecated.**   
> Use the camera2Interop extension function on UseCase.Builder (e.g., 'builder.camera2Interop { setPhysicalCameraId(physicalCameraId) }') or SessionConfig.Builder for capture request options and callbacks instead.

Creates an Extender that can be used to add Camera2 options to another Builder.

| Parameters |
|---|---|
| `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?>` | the type being built by the extendable builder. |
| `baseBuilder: https://developer.android.com/reference/kotlin/androidx/camera/core/ExtendableBuilder<T>` | The builder being extended. |

## Public functions

### setCaptureRequestOption

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)

```
fun <ValueT : Any?> [setCaptureRequestOption](https://developer.android.com/reference/kotlin/androidx/camera/camera2/interop/Camera2Interop.Extender#setCaptureRequestOption(android.hardware.camera2.CaptureRequest.Key,kotlin.Any))(
    key: CaptureRequest.Key<ValueT>,
    value: ValueT
): Camera2Interop.Extender<T>
```

> [!CAUTION]
> **This function is deprecated.**   
> Use the camera2Interop extension function on UseCase.Builder (e.g., 'builder.camera2Interop { setPhysicalCameraId(physicalCameraId) }') or SessionConfig.Builder for capture request options and callbacks instead.

Sets a `https://developer.android.com/reference/android/hardware/camera2/CaptureRequest.Key.html` and Value on the configuration.

The value will override any value set by CameraX internally with the risk of interfering with some CameraX CameraControl APIs as well as 3A behavior. When applied to an `https://developer.android.com/reference/kotlin/androidx/camera/core/ImageCapture.Builder`, options set for still capture requests override corresponding keys set in repeating requests.

| Parameters |
|---|---|
| `<ValueT : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?>` | The type of the value. |
| `key: https://developer.android.com/reference/android/hardware/camera2/CaptureRequest.Key.html<ValueT>` | The `https://developer.android.com/reference/android/hardware/camera2/CaptureRequest.Key.html` which will be set. |
| `value: ValueT` | The value for the key. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/camera2/interop/Camera2Interop.Extender<T>` | The current Extender. |

### setDeviceStateCallback

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)

```
fun [setDeviceStateCallback](https://developer.android.com/reference/kotlin/androidx/camera/camera2/interop/Camera2Interop.Extender#setDeviceStateCallback(android.hardware.camera2.CameraDevice.StateCallback))(stateCallback: CameraDevice.StateCallback): Camera2Interop.Extender<T>
```

> [!CAUTION]
> **This function is deprecated.**   
> Use the camera2Interop extension function on UseCase.Builder (e.g., 'builder.camera2Interop { setPhysicalCameraId(physicalCameraId) }') or SessionConfig.Builder for capture request options and callbacks instead.

Sets a `https://developer.android.com/reference/android/hardware/camera2/CameraDevice.StateCallback.html`.

The caller is expected to use the `https://developer.android.com/reference/android/hardware/camera2/CameraDevice.html` instance accessed through the callback methods responsibly. Generally safe usages include: (1) querying the device for its id, (2) using the callbacks to determine what state the device is currently in. Generally unsafe usages include: (1) creating a new `https://developer.android.com/reference/android/hardware/camera2/CameraCaptureSession.html`, (2) creating a new `https://developer.android.com/reference/android/hardware/camera2/CaptureRequest.html`, (3) closing the device. When the caller uses the device beyond the safe usage limits, the usage may still work in conjunction with CameraX, but any strong guarantees provided by CameraX about the validity of the camera state become void.

| Parameters |
|---|---|
| `stateCallback: https://developer.android.com/reference/android/hardware/camera2/CameraDevice.StateCallback.html` | The `https://developer.android.com/reference/android/hardware/camera2/CameraDevice.StateCallback.html`. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/camera2/interop/Camera2Interop.Extender<T>` | The current Extender. |

### setPhysicalCameraId

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)

```
@RequiresApi(value = 28)
fun [setPhysicalCameraId](https://developer.android.com/reference/kotlin/androidx/camera/camera2/interop/Camera2Interop.Extender#setPhysicalCameraId(kotlin.String))(cameraId: String): Camera2Interop.Extender<T>
```

> [!CAUTION]
> **This function is deprecated.**   
> Use the camera2Interop extension function on UseCase.Builder (e.g., 'builder.camera2Interop { setPhysicalCameraId(physicalCameraId) }') or SessionConfig.Builder for capture request options and callbacks instead.

Set the ID of the physical camera to get output from.

In the case one logical camera is made up of multiple physical cameras, this call forces the physical camera with the specified camera ID to produce image.

The valid physical camera IDs can be queried by `CameraCharacteristics .getPhysicalCameraIds` on API \>= 28. Passing in an invalid physical camera ID will be ignored.

On API \<= 27, the physical camera ID will be ignored since logical camera is not supported on these API levels.

Currently it doesn't support binding use cases with different physical camera IDs. If use cases with different physical camera IDs are bound at the same time, an `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` will be thrown.

| Parameters |
|---|---|
| `cameraId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | The desired camera ID. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/camera2/interop/Camera2Interop.Extender<T>` | The current Extender. |

### setSessionCaptureCallback

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)

```
fun [setSessionCaptureCallback](https://developer.android.com/reference/kotlin/androidx/camera/camera2/interop/Camera2Interop.Extender#setSessionCaptureCallback(android.hardware.camera2.CameraCaptureSession.CaptureCallback))(
    captureCallback: CameraCaptureSession.CaptureCallback
): Camera2Interop.Extender<T>
```

> [!CAUTION]
> **This function is deprecated.**   
> Use the camera2Interop extension function on UseCase.Builder (e.g., 'builder.camera2Interop { setPhysicalCameraId(physicalCameraId) }') or SessionConfig.Builder for capture request options and callbacks instead.

Sets a `https://developer.android.com/reference/android/hardware/camera2/CameraCaptureSession.CaptureCallback.html`.

The caller is expected to use the `https://developer.android.com/reference/android/hardware/camera2/CameraCaptureSession.html` instance accessed through the callback methods responsibly. Generally safe usages include: (1) querying the session for its properties. Generally unsafe usages include: (1) submitting a new `https://developer.android.com/reference/android/hardware/camera2/CaptureRequest.html`, (2) stopping an existing `https://developer.android.com/reference/android/hardware/camera2/CaptureRequest.html`, (3) closing the session, (4) attaching a new `https://developer.android.com/reference/android/view/Surface.html` to the session. When the caller uses the session beyond the safe usage limits, the usage may still work in conjunction with CameraX, but any strong guarantees provided by CameraX about the validity of the camera state become void.

The caller is generally free to use the `https://developer.android.com/reference/android/hardware/camera2/CaptureRequest.html` and `https://developer.android.com/reference/android/hardware/camera2/CaptureRequest.html` instances accessed through the callback methods.

| Parameters |
|---|---|
| `captureCallback: https://developer.android.com/reference/android/hardware/camera2/CameraCaptureSession.CaptureCallback.html` | The `https://developer.android.com/reference/android/hardware/camera2/CameraCaptureSession.CaptureCallback.html`. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/camera2/interop/Camera2Interop.Extender<T>` | The current Extender. |

### setSessionStateCallback

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)

```
fun [setSessionStateCallback](https://developer.android.com/reference/kotlin/androidx/camera/camera2/interop/Camera2Interop.Extender#setSessionStateCallback(android.hardware.camera2.CameraCaptureSession.StateCallback))(
    stateCallback: CameraCaptureSession.StateCallback
): Camera2Interop.Extender<T>
```

> [!CAUTION]
> **This function is deprecated.**   
> Use the camera2Interop extension function on UseCase.Builder (e.g., 'builder.camera2Interop { setPhysicalCameraId(physicalCameraId) }') or SessionConfig.Builder for capture request options and callbacks instead.

Sets a `https://developer.android.com/reference/android/hardware/camera2/CameraCaptureSession.StateCallback.html`.

The caller is expected to use the `https://developer.android.com/reference/android/hardware/camera2/CameraCaptureSession.html` instance accessed through the callback methods responsibly. Generally safe usages include: (1) querying the session for its properties, (2) using the callbacks to determine what state the session is currently in. Generally unsafe usages include: (1) submitting a new `https://developer.android.com/reference/android/hardware/camera2/CameraCaptureSession.html`, (2) stopping an existing `https://developer.android.com/reference/android/hardware/camera2/CaptureRequest.html`, (3) closing the session, (4) attaching a new `https://developer.android.com/reference/android/view/Surface.html` to the session. When the caller uses the session beyond the safe usage limits, the usage may still work in conjunction with CameraX, but any strong guarantees provided by CameraX about the validity of the camera state become void.

| Parameters |
|---|---|
| `stateCallback: https://developer.android.com/reference/android/hardware/camera2/CameraCaptureSession.StateCallback.html` | The `https://developer.android.com/reference/android/hardware/camera2/CameraCaptureSession.StateCallback.html`. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/camera2/interop/Camera2Interop.Extender<T>` | The current Extender. |

### setStreamUseCase

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

```
@RequiresApi(value = 33)
fun [setStreamUseCase](https://developer.android.com/reference/kotlin/androidx/camera/camera2/interop/Camera2Interop.Extender#setStreamUseCase(kotlin.Long))(streamUseCase: Long): Camera2Interop.Extender<T>
```

> [!CAUTION]
> **This function is deprecated.**   
> Use the camera2Interop extension function on UseCase.Builder (e.g., 'builder.camera2Interop { setPhysicalCameraId(physicalCameraId) }') or SessionConfig.Builder for capture request options and callbacks instead.

Sets a stream use case flag on the given extendable builder.

Requires API 33 or above.

Calling this method will set the stream useCase for the stream associated with the surface whose container class is the UseCase. Valid use cases available on devices can be found in `https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics.html#SCALER_AVAILABLE_STREAM_USE_CASES` The app should make sure the input argument is in the list of supported use cases first.

If a unsupported value is provided, `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` will be thrown.

| Parameters |
|---|---|
| `streamUseCase: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | The stream use case to set. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/camera2/interop/Camera2Interop.Extender<T>` | The current Extender. |

| See also |
|---|---|
| `https://developer.android.com/reference/android/hardware/camera2/params/OutputConfiguration.html#setStreamUseCase(long)` | to see how Camera2 framework uses this. |