# CameraId

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

*** ** * ** ***


```
value class CameraId
```

<br />

*** ** * ** ***

A type-safe identifier for a camera device.

This value class wraps a `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` representation of a camera ID. Using `https://developer.android.com/reference/kotlin/androidx/camera/common/CameraId` instead of raw strings or integers helps prevent type confusion and ensures that APIs receiving or returning camera identifiers are self-documenting and type-safe.

`https://developer.android.com/reference/kotlin/androidx/camera/common/CameraId` instances are typically created using the factory methods in the companion object: `https://developer.android.com/reference/kotlin/androidx/camera/common/CameraId#fromCamera2Id(kotlin.String)` for Camera2 string identifiers, or `https://developer.android.com/reference/kotlin/androidx/camera/common/CameraId#fromCamera1Id(kotlin.Int)` for legacy Camera1 integer identifiers.

## Summary

| ### Public companion functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/common/CameraId` | `https://developer.android.com/reference/kotlin/androidx/camera/common/CameraId#fromCamera1Id(kotlin.Int)(value: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Creates a `https://developer.android.com/reference/kotlin/androidx/camera/common/CameraId` from a legacy Camera1 camera identifier integer. |
| `https://developer.android.com/reference/kotlin/androidx/camera/common/CameraId` | `https://developer.android.com/reference/kotlin/androidx/camera/common/CameraId#fromCamera2Id(kotlin.String)(value: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` Creates a `https://developer.android.com/reference/kotlin/androidx/camera/common/CameraId` from a Camera2 camera identifier string. |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/common/CameraId#CameraId(kotlin.String)(value: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` |

| ### Public functions |
|---|---|
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/camera/common/CameraId#toString()()` Returns a string representation of the `https://developer.android.com/reference/kotlin/androidx/camera/common/CameraId` for debugging purposes, in the format "CameraId-value". |

| ### Public properties |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/camera/common/CameraId#value()` The underlying string representation of the camera identifier. |

## Public companion functions

### fromCamera1Id

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

```
fun fromCamera1Id(value: Int): CameraId
```

Creates a `https://developer.android.com/reference/kotlin/androidx/camera/common/CameraId` from a legacy Camera1 camera identifier integer.

Camera1 identifiers are typically zero-based indices used with `android.hardware.Camera.open(int)`.

| Parameters |
|---|---|
| `value: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The Camera1 integer identifier. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/common/CameraId` | A `https://developer.android.com/reference/kotlin/androidx/camera/common/CameraId` representing the given identifier as a string. |

### fromCamera2Id

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

```
fun fromCamera2Id(value: String): CameraId
```

Creates a `https://developer.android.com/reference/kotlin/androidx/camera/common/CameraId` from a Camera2 camera identifier string.

Camera2 identifiers are typically obtained from `android.hardware.camera2.CameraManager.getCameraIdList()`.

| Parameters |
|---|---|
| `value: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | The Camera2 identifier string. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/common/CameraId` | A `https://developer.android.com/reference/kotlin/androidx/camera/common/CameraId` representing the given identifier. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | if `https://developer.android.com/reference/kotlin/androidx/camera/common/CameraId.Companion#fromCamera2Id(kotlin.String)` is empty. |

## Public constructors

### CameraId

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

```
CameraId(value: String)
```

## Public functions

### toString

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

Returns a string representation of the `https://developer.android.com/reference/kotlin/androidx/camera/common/CameraId` for debugging purposes, in the format "CameraId-value".

## Public properties

### value

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

```
val value: String
```

The underlying string representation of the camera identifier. Must not be empty.