# CameraCharacteristicsMetadata

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/Metadata.kt+class:androidx.camera.common.CameraCharacteristicsMetadata) Added in [1.7.0-rc02](https://developer.android.com/jetpack/androidx/releases/camera#1.7.0-rc02)

*** ** * ** ***


```
public interface CameraCharacteristicsMetadata extends Metadata, UnsafeWrapper
```

<br />

Known direct subclasses [CameraCharacteristicsWrapper](https://developer.android.com/reference/androidx/camera/common/CameraCharacteristicsWrapper), [CameraExtensionCharacteristicsWrapper](https://developer.android.com/reference/androidx/camera/common/CameraExtensionCharacteristicsWrapper)

|---|---|
| `https://developer.android.com/reference/androidx/camera/common/CameraCharacteristicsWrapper` | Wrapper interface providing compatibility-focused access to `https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics.html`. |
| `https://developer.android.com/reference/androidx/camera/common/CameraExtensionCharacteristicsWrapper` | Compatibility wrapper around `https://developer.android.com/reference/android/hardware/camera2/CameraExtensionCharacteristics.html`. |

Known indirect subclasses [FakeCameraCharacteristics](https://developer.android.com/reference/androidx/camera/common/testing/FakeCameraCharacteristics), [FakeCameraExtensionCharacteristics](https://developer.android.com/reference/androidx/camera/common/testing/FakeCameraExtensionCharacteristics)

|---|---|
| `https://developer.android.com/reference/androidx/camera/common/testing/FakeCameraCharacteristics` | A fake implementation of `https://developer.android.com/reference/androidx/camera/common/CameraCharacteristicsWrapper` for testing. |
| `https://developer.android.com/reference/androidx/camera/common/testing/FakeCameraExtensionCharacteristics` | A fake implementation of `https://developer.android.com/reference/androidx/camera/common/CameraExtensionCharacteristicsWrapper` for testing. |

*** ** * ** ***

An interface that provides compatibility-focused, read-only query access to `https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics.html`.

Use this interface to query camera capabilities, physical properties, and supported configurations. Implementing classes can abstract OS version differences and cache expensive-to-retrieve properties to ensure efficient access across all API levels.

`CameraCharacteristicsMetadata` extends `https://developer.android.com/reference/androidx/camera/common/Metadata`, supporting type-safe retrieval of custom library-defined metadata keys via `https://developer.android.com/reference/androidx/camera/common/Metadata.Key` in addition to native `https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics.Key.html` keys.

NOTE: This interface is not stable for inheritance. Do not implement this interface directly. For testing, use the fakes in the `androidx.camera.common.testing` package.

### Example

Querying native and custom keys:

```
val characteristics: CameraCharacteristicsMetadata = ...

// Query a native CameraCharacteristics key:
val lensFacing: Int? = characteristics[CameraCharacteristics.LENS_FACING]

// Query a custom Metadata key:
val customValue: String? = characteristics[MY_CUSTOM_METADATA_KEY]
```

## Summary

| ### Public methods |
|---|---|
| `abstract T` | `<T extends https://developer.android.com/reference/java/lang/Object.html> https://developer.android.com/reference/androidx/camera/common/CameraCharacteristicsMetadata#get(android.hardware.camera2.CameraCharacteristics.Key)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics.Key.html<@https://developer.android.com/reference/androidx/annotation/NonNull T> key)` Retrieves the value of the specified `https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics.Key.html`. |
| `default @https://developer.android.com/reference/androidx/annotation/NonNull T` | `<T extends https://developer.android.com/reference/java/lang/Object.html> https://developer.android.com/reference/androidx/camera/common/CameraCharacteristicsMetadata#getOrDefault(android.hardware.camera2.CameraCharacteristics.Key,kotlin.Any)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics.Key.html<@https://developer.android.com/reference/androidx/annotation/NonNull T> key, @https://developer.android.com/reference/androidx/annotation/NonNull T default )` Retrieves the value of the specified `https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics.Key.html`, or returns `https://developer.android.com/reference/androidx/camera/common/CameraCharacteristicsMetadata#getOrDefault(android.hardware.camera2.CameraCharacteristics.Key,kotlin.Any)` if the value is `null` or the key is unsupported. |

### Inherited methods

From [androidx.camera.common.Metadata](https://developer.android.com/reference/androidx/camera/common/Metadata) `abstract T` `<T extends https://developer.android.com/reference/java/lang/Object.html> https://developer.android.com/reference/androidx/camera/common/Metadata#get(androidx.camera.common.Metadata.Key)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/common/Metadata.Key<@https://developer.android.com/reference/androidx/annotation/NonNull T> key)`

Retrieves the value associated with the specified `https://developer.android.com/reference/androidx/camera/common/Metadata.Key`.
`abstract @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Set.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/common/Metadata.Key<@https://developer.android.com/reference/androidx/annotation/NonNull ?>>` `https://developer.android.com/reference/androidx/camera/common/Metadata#getMetadataKeys()()`

The set of all custom `https://developer.android.com/reference/androidx/camera/common/Metadata.Key`s currently available in this container.
`default @https://developer.android.com/reference/androidx/annotation/NonNull T` `<T extends https://developer.android.com/reference/java/lang/Object.html> https://developer.android.com/reference/androidx/camera/common/Metadata#getOrDefault(androidx.camera.common.Metadata.Key,kotlin.Any)(
@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/common/Metadata.Key<@https://developer.android.com/reference/androidx/annotation/NonNull T> key,
@https://developer.android.com/reference/androidx/annotation/NonNull T default
)`

Retrieves the value associated with the specified `https://developer.android.com/reference/androidx/camera/common/Metadata.Key`, or returns `https://developer.android.com/reference/androidx/camera/common/Metadata#getOrDefault(androidx.camera.common.Metadata.Key,kotlin.Any)` if the key is not present.
From [androidx.camera.common.UnsafeWrapper](https://developer.android.com/reference/androidx/camera/common/UnsafeWrapper) `abstract T` `<T extends https://developer.android.com/reference/java/lang/Object.html> https://developer.android.com/reference/androidx/camera/common/UnsafeWrapper#unwrapAs(java.lang.Class)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Class.html<@https://developer.android.com/reference/androidx/annotation/NonNull T> type)`

Attempts to unwrap this object into the specified underlying `https://developer.android.com/reference/androidx/camera/common/UnsafeWrapper#unwrapAs(java.lang.Class)`.

## Public methods

### get

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

```
abstract T <T extends Object> get(@NonNull CameraCharacteristics.Key<@NonNull T> key)
```

Retrieves the value of the specified `https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics.Key.html`.

| Parameters |
|---|---|
| `<T extends https://developer.android.com/reference/java/lang/Object.html>` | The type of the value (must be non-nullable). |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics.Key.html<@https://developer.android.com/reference/androidx/annotation/NonNull T> key` | The key to query. |

| Returns |
|---|---|
| `T` | The value of the key, or `null` if the key is not present or unsupported. |

### getOrDefault

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

```
default @NonNull T <T extends Object> getOrDefault(
    @NonNull CameraCharacteristics.Key<@NonNull T> key,
    @NonNull T default
)
```

Retrieves the value of the specified `https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics.Key.html`, or returns `https://developer.android.com/reference/androidx/camera/common/CameraCharacteristicsMetadata#getOrDefault(android.hardware.camera2.CameraCharacteristics.Key,kotlin.Any)` if the value is `null` or the key is unsupported.

| Parameters |
|---|---|
| `<T extends https://developer.android.com/reference/java/lang/Object.html>` | The type of the value (must be non-nullable). |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics.Key.html<@https://developer.android.com/reference/androidx/annotation/NonNull T> key` | The key to query. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull T default` | The value to return if the key is not present or unsupported. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull T` | The value of the key, or `https://developer.android.com/reference/androidx/camera/common/CameraCharacteristicsMetadata#getOrDefault(android.hardware.camera2.CameraCharacteristics.Key,kotlin.Any)` if null. |