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

```
public final 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/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/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/androidx/camera/core/CameraSelector#of(androidx.camera.core.CameraIdentifier...)` factory method. This class also includes convenience methods like `https://developer.android.com/reference/androidx/camera/core/CameraIdentifier#isOf(androidx.camera.core.Camera)` to check if this identifier corresponds to a given `https://developer.android.com/reference/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/androidx/camera/core/CameraSelector` with the `https://developer.android.com/reference/androidx/camera/core/CameraSelector#of(androidx.camera.core.CameraIdentifier...)` static factory method.

```
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/androidx/camera/core/CameraInfo` for a specific `CameraIdentifier`, you must use a `https://developer.android.com/reference/androidx/camera/core/CameraSelector` to query the `https://developer.android.com/reference/androidx/camera/core/CameraProvider`. This ensures that the camera is currently available.

```
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/androidx/camera/core/CameraInfo#getCameraIdentifier()` |   |
| `https://developer.android.com/reference/androidx/camera/core/CameraSelector#of(androidx.camera.core.CameraIdentifier...)` |   |
| `https://developer.android.com/reference/androidx/camera/core/CameraPresenceListener` |   |

## Summary

| ### Public methods |
|---|---|
| `boolean` | `https://developer.android.com/reference/androidx/camera/core/CameraIdentifier#equals(kotlin.Any)(https://developer.android.com/reference/java/lang/Object.html other)` |
| `int` | `https://developer.android.com/reference/androidx/camera/core/CameraIdentifier#hashCode()()` |
| `final boolean` | `https://developer.android.com/reference/androidx/camera/core/CameraIdentifier#isOf(androidx.camera.core.Camera)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/core/Camera camera)` Checks if this identifier corresponds to the given `https://developer.android.com/reference/androidx/camera/core/Camera` instance. |
| `final boolean` | `https://developer.android.com/reference/androidx/camera/core/CameraIdentifier#isOf(androidx.camera.core.CameraInfo)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/core/CameraInfo cameraInfo)` Checks if this identifier corresponds to the given `https://developer.android.com/reference/androidx/camera/core/CameraInfo` instance. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/camera/core/CameraIdentifier#toString()()` |

## Public methods

### equals

```
public boolean equals(Object other)
```

### hashCode

```
public int hashCode()
```

### isOf

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

```
public final boolean isOf(@NonNull Camera camera)
```

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

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

**Usage Example:**

```
// 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)

```
public final boolean isOf(@NonNull CameraInfo cameraInfo)
```

Checks if this identifier corresponds to the given `https://developer.android.com/reference/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/androidx/camera/core/CameraProvider#availableCameraInfos()`.

### toString

```
public @NonNull String toString()
```