# 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
public final class Camera2Interop.Extender<T extends Object>
```

<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/androidx/camera/camera2/interop/Camera2Interop.Extender#(androidx.camera.core.ExtendableBuilder)` to add Camera2 options.

Use `https://developer.android.com/reference/androidx/camera/camera2/interop/Camera2Interop#forUseCase(androidx.core.util.Consumer)`, `https://developer.android.com/reference/androidx/camera/camera2/interop/Camera2Interop#forImageCapture(androidx.core.util.Consumer)`, or `https://developer.android.com/reference/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 extends https://developer.android.com/reference/java/lang/Object.html>` | the type being built by the extendable builder. |

## Summary

| ### Public constructors |
|---|
| `<T extends https://developer.android.com/reference/java/lang/Object.html> [Extender](https://developer.android.com/reference/androidx/camera/camera2/interop/Camera2Interop.Extender#Extender(androidx.camera.core.ExtendableBuilder))(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/core/ExtendableBuilder<@https://developer.android.com/reference/androidx/annotation/NonNull T> baseBuilder)` **This method 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 methods |
|---|---|
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/camera2/interop/Camera2Interop.Extender<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `<ValueT extends https://developer.android.com/reference/java/lang/Object.html> [setCaptureRequestOption](https://developer.android.com/reference/androidx/camera/camera2/interop/Camera2Interop.Extender#setCaptureRequestOption(android.hardware.camera2.CaptureRequest.Key,kotlin.Any))( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/hardware/camera2/CaptureRequest.Key.html<@https://developer.android.com/reference/androidx/annotation/NonNull ValueT> key, @https://developer.android.com/reference/androidx/annotation/NonNull ValueT value )` **This method 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. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/camera2/interop/Camera2Interop.Extender<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `[setDeviceStateCallback](https://developer.android.com/reference/androidx/camera/camera2/interop/Camera2Interop.Extender#setDeviceStateCallback(android.hardware.camera2.CameraDevice.StateCallback))( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/hardware/camera2/CameraDevice.StateCallback.html stateCallback )` **This method 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. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/camera2/interop/Camera2Interop.Extender<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `@https://developer.android.com/reference/androidx/annotation/RequiresApi(value = 28) [setPhysicalCameraId](https://developer.android.com/reference/androidx/camera/camera2/interop/Camera2Interop.Extender#setPhysicalCameraId(kotlin.String))(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html cameraId)` **This method 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. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/camera2/interop/Camera2Interop.Extender<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `[setSessionCaptureCallback](https://developer.android.com/reference/androidx/camera/camera2/interop/Camera2Interop.Extender#setSessionCaptureCallback(android.hardware.camera2.CameraCaptureSession.CaptureCallback))( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/hardware/camera2/CameraCaptureSession.CaptureCallback.html captureCallback )` **This method 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. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/camera2/interop/Camera2Interop.Extender<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `[setSessionStateCallback](https://developer.android.com/reference/androidx/camera/camera2/interop/Camera2Interop.Extender#setSessionStateCallback(android.hardware.camera2.CameraCaptureSession.StateCallback))( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/hardware/camera2/CameraCaptureSession.StateCallback.html stateCallback )` **This method 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. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/camera2/interop/Camera2Interop.Extender<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `@https://developer.android.com/reference/androidx/annotation/RequiresApi(value = 33) [setStreamUseCase](https://developer.android.com/reference/androidx/camera/camera2/interop/Camera2Interop.Extender#setStreamUseCase(kotlin.Long))(long streamUseCase)` **This method 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

```
public <T extends Object> [Extender](https://developer.android.com/reference/androidx/camera/camera2/interop/Camera2Interop.Extender#Extender(androidx.camera.core.ExtendableBuilder))(@NonNull ExtendableBuilder<@NonNull T> baseBuilder)
```

> [!CAUTION]
> **This method 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 extends https://developer.android.com/reference/java/lang/Object.html>` | the type being built by the extendable builder. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/core/ExtendableBuilder<@https://developer.android.com/reference/androidx/annotation/NonNull T> baseBuilder` | The builder being extended. |

## Public methods

### 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)

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

> [!CAUTION]
> **This method 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/androidx/camera/core/ImageCapture.Builder`, options set for still capture requests override corresponding keys set in repeating requests.

| Parameters |
|---|---|
| `<ValueT extends https://developer.android.com/reference/java/lang/Object.html>` | The type of the value. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/hardware/camera2/CaptureRequest.Key.html<@https://developer.android.com/reference/androidx/annotation/NonNull ValueT> key` | The `https://developer.android.com/reference/android/hardware/camera2/CaptureRequest.Key.html` which will be set. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull ValueT value` | The value for the key. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/camera2/interop/Camera2Interop.Extender<@https://developer.android.com/reference/androidx/annotation/NonNull 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)

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

> [!CAUTION]
> **This method 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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/hardware/camera2/CameraDevice.StateCallback.html stateCallback` | The `https://developer.android.com/reference/android/hardware/camera2/CameraDevice.StateCallback.html`. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/camera2/interop/Camera2Interop.Extender<@https://developer.android.com/reference/androidx/annotation/NonNull 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)
public final @NonNull Camera2Interop.Extender<@NonNull T> [setPhysicalCameraId](https://developer.android.com/reference/androidx/camera/camera2/interop/Camera2Interop.Extender#setPhysicalCameraId(kotlin.String))(@NonNull String cameraId)
```

> [!CAUTION]
> **This method 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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html cameraId` | The desired camera ID. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/camera2/interop/Camera2Interop.Extender<@https://developer.android.com/reference/androidx/annotation/NonNull 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)

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

> [!CAUTION]
> **This method 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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/hardware/camera2/CameraCaptureSession.CaptureCallback.html captureCallback` | The `https://developer.android.com/reference/android/hardware/camera2/CameraCaptureSession.CaptureCallback.html`. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/camera2/interop/Camera2Interop.Extender<@https://developer.android.com/reference/androidx/annotation/NonNull 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)

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

> [!CAUTION]
> **This method 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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/hardware/camera2/CameraCaptureSession.StateCallback.html stateCallback` | The `https://developer.android.com/reference/android/hardware/camera2/CameraCaptureSession.StateCallback.html`. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/camera2/interop/Camera2Interop.Extender<@https://developer.android.com/reference/androidx/annotation/NonNull 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)
public final @NonNull Camera2Interop.Extender<@NonNull T> [setStreamUseCase](https://developer.android.com/reference/androidx/camera/camera2/interop/Camera2Interop.Extender#setStreamUseCase(kotlin.Long))(long streamUseCase)
```

> [!CAUTION]
> **This method 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 |
|---|---|
| `long streamUseCase` | The stream use case to set. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/camera2/interop/Camera2Interop.Extender<@https://developer.android.com/reference/androidx/annotation/NonNull 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. |