# CameraIdentifier

Artifact: [androidx.camera:camera-core](https://developer.android.com/jetpack/androidx/releases/camera) [View Source](https://cs.android.com/search?q=file:androidx/camera/core/CameraIdentifier.kt+class:androidx.camera.core.CameraIdentifier) Added in [1.6.0](https://developer.android.com/jetpack/androidx/releases/camera#1.6.0)

*** ** * ** ***

<br />

```
class CameraIdentifier
```

<br />

*** ** * ** ***

An opaque, stable identifier for a camera device recognized by CameraX.

This identifier is designed to be unique and stable for a specific camera device across application sessions and device connect/disconnect events, provided the underlying system can consistently identify the camera. It serves as a reliable key for uniquely identifying cameras within CameraX APIs, such as in `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraPresenceListener` callbacks.

Applications should not attempt to parse the string representation of this identifier or assume any particular format for its internal value, as it may change across CameraX versions or device implementations.

Instances of `CameraIdentifier` are vended by CameraX (e.g., via `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraInfo#getCameraIdentifier()`). Applications should not instantiate this class directly.

To re-select a camera for binding, use the `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector#of(androidx.camera.core.CameraIdentifier...)` factory method. This class also includes convenience methods like `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraIdentifier#isOf(androidx.camera.core.Camera)` to check if this identifier corresponds to a given `https://developer.android.com/reference/kotlin/androidx/camera/core/Camera` instance.

**Selecting a Specific Camera**

The primary way to use a `CameraIdentifier` is to re-select that specific camera for binding. This is done by creating a `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector` with the `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector#of(androidx.camera.core.CameraIdentifier...)` static factory method.

```kotlin
val cameraProvider = ...
val specificId = ... // From a listener or saved preferences

// Create a selector that will only match the specific camera
val selector = CameraSelector.of(specificId)

try {
// Bind use cases to this exact camera
val camera = cameraProvider.bindToLifecycle(lifecycleOwner, selector, useCaseGroup)
} catch (e: IllegalArgumentException) {
// This occurs if the camera with the specific ID is no longer available.
}
```

**Obtaining CameraInfo from an Identifier**

To get the `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraInfo` for a specific `CameraIdentifier`, you must use a `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector` to query the `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraProvider`. This ensures that the camera is currently available.

```kotlin
val cameraProvider = ...
val identifier = ...

try {
val info = cameraProvider.getCameraInfo(CameraSelector.of(identifier))
// Use the CameraInfo object...
} catch (e: IllegalArgumentException) {
// This exception is thrown if the camera corresponding to the
// identifier is not currently available.
}
```

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraInfo#getCameraIdentifier()` |   |
| `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector#of(androidx.camera.core.CameraIdentifier...)` |   |
| `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraPresenceListener` |   |

## Summary

| ### Public functions |
|---|---|
| `open operator https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraIdentifier#equals(kotlin.Any)(other: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?)` |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraIdentifier#hashCode()()` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraIdentifier#isOf(androidx.camera.core.Camera)(camera: https://developer.android.com/reference/kotlin/androidx/camera/core/Camera)` Checks if this identifier corresponds to the given `https://developer.android.com/reference/kotlin/androidx/camera/core/Camera` instance. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraIdentifier#isOf(androidx.camera.core.CameraInfo)(cameraInfo: https://developer.android.com/reference/kotlin/androidx/camera/core/CameraInfo)` Checks if this identifier corresponds to the given `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraInfo` instance. |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraIdentifier#toString()()` |

## Public functions

### equals

```
open operator fun equals(other: Any?): Boolean
```

### hashCode

```
open fun hashCode(): Int
```

### isOf

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

```
fun isOf(camera: Camera): Boolean
```

Checks if this identifier corresponds to the given `https://developer.android.com/reference/kotlin/androidx/camera/core/Camera` instance.

This is a convenience method that simplifies checking if a `CameraIdentifier` matches a currently bound `Camera` object.

**Usage Example:**

```kotlin
// Instead of:
// if (identifier.equals(myCamera.cameraInfo.cameraIdentifier)) { ... }

// You can write:
if (identifier.isOf(myCamera)) { ... }
```

### isOf

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

```
fun isOf(cameraInfo: CameraInfo): Boolean
```

Checks if this identifier corresponds to the given `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraInfo` instance.

This is a convenience method for checking against a `CameraInfo` object, which might be retrieved from `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraProvider#availableCameraInfos()`.

### toString

```
open fun toString(): String
```