Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Ctors](https://developer.android.com/reference/android/hardware/camera2/CameraManager.AvailabilityCallback#pubctors) \| [Methods](https://developer.android.com/reference/android/hardware/camera2/CameraManager.AvailabilityCallback#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/hardware/camera2/CameraManager.AvailabilityCallback#inhmethods)

# CameraManager.AvailabilityCallback

*** ** * ** ***

` public static abstract class CameraManager.AvailabilityCallback `   
` extends https://developer.android.com/reference/java/lang/Object ` ` `

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.hardware.camera2.CameraManager.AvailabilityCallback |

<br />

*** ** * ** ***

A callback for camera devices becoming available or unavailable to open.

Cameras become available when they are no longer in use, or when a new removable camera is connected. They become unavailable when some application or service starts using a camera, or when a removable camera is disconnected.

Extend this callback and pass an instance of the subclass to `https://developer.android.com/reference/android/hardware/camera2/CameraManager#registerAvailabilityCallback(android.hardware.camera2.CameraManager.AvailabilityCallback,%20android.os.Handler)` to be notified of such availability changes.

<br />

**See also:**

- `https://developer.android.com/reference/android/hardware/camera2/CameraManager#registerAvailabilityCallback(android.hardware.camera2.CameraManager.AvailabilityCallback,%20android.os.Handler)`

## Summary

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/hardware/camera2/CameraManager.AvailabilityCallback#AvailabilityCallback()() ` |

| ### Public methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/android/hardware/camera2/CameraManager.AvailabilityCallback#onCameraAccessPrioritiesChanged()() ` Called whenever camera access priorities change. |
| ` void` | ` https://developer.android.com/reference/android/hardware/camera2/CameraManager.AvailabilityCallback#onCameraAvailable(java.lang.String)(https://developer.android.com/reference/java/lang/String cameraId) ` A new camera has become available to use. |
| ` void` | ` https://developer.android.com/reference/android/hardware/camera2/CameraManager.AvailabilityCallback#onCameraRemoved(java.lang.String)(https://developer.android.com/reference/java/lang/String cameraId) ` A camera device has been physically removed or is no longer available to the system. |
| ` void` | ` https://developer.android.com/reference/android/hardware/camera2/CameraManager.AvailabilityCallback#onCameraUnavailable(java.lang.String)(https://developer.android.com/reference/java/lang/String cameraId) ` A previously-available camera has become unavailable for use. |
| ` void` | ` https://developer.android.com/reference/android/hardware/camera2/CameraManager.AvailabilityCallback#onPhysicalCameraAvailable(java.lang.String,%20java.lang.String)(https://developer.android.com/reference/java/lang/String cameraId, https://developer.android.com/reference/java/lang/String physicalCameraId) ` A physical camera has become available for use again. |
| ` void` | ` https://developer.android.com/reference/android/hardware/camera2/CameraManager.AvailabilityCallback#onPhysicalCameraUnavailable(java.lang.String,%20java.lang.String)(https://developer.android.com/reference/java/lang/String cameraId, https://developer.android.com/reference/java/lang/String physicalCameraId) ` A previously-available physical camera has become unavailable for use. |

### Inherited methods

From class ` https://developer.android.com/reference/java/lang/Object ` ` https://developer.android.com/reference/java/lang/Object` ` https://developer.android.com/reference/java/lang/Object#clone()() `

Creates and returns a copy of this object.
` boolean` ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) `

Indicates whether some other object is "equal to" this one.
` void` ` https://developer.android.com/reference/java/lang/Object#finalize()() `

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
` final https://developer.android.com/reference/java/lang/Class<?>` ` https://developer.android.com/reference/java/lang/Object#getClass()() `

Returns the runtime class of this `Object`.
` int` ` https://developer.android.com/reference/java/lang/Object#hashCode()() `

Returns a hash code value for the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#notify()() `

Wakes up a single thread that is waiting on this object's monitor.
` final void` ` https://developer.android.com/reference/java/lang/Object#notifyAll()() `

Wakes up all threads that are waiting on this object's monitor.
` https://developer.android.com/reference/java/lang/String` ` https://developer.android.com/reference/java/lang/Object#toString()() `

Returns a string representation of the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait()() `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*.

## Public constructors

### AvailabilityCallback

```
public AvailabilityCallback ()
```

<br />

<br />

## Public methods

### onCameraAccessPrioritiesChanged

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void onCameraAccessPrioritiesChanged ()
```

Called whenever camera access priorities change.

Notification that camera access priorities have changed and the camera may now be openable. An application that was previously denied camera access due to a higher-priority user already using the camera, or that was disconnected from an active camera session due to a higher-priority user trying to open the camera, should try to open the camera again if it still wants to use it. Note that multiple applications may receive this callback at the same time, and only one of them will succeed in opening the camera in practice, depending on exact access priority levels and timing. This method is useful in cases where multiple applications may be in the resumed state at the same time, and the user switches focus between them, or if the current camera-using application moves between full-screen and Picture-in-Picture (PiP) states. In such cases, the camera available/unavailable callbacks will not be invoked, but another application may now have higher priority for camera access than the current camera-using application.

The default implementation of this method does nothing.

<br />

<br />

### onCameraAvailable

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void onCameraAvailable (String cameraId)
```

A new camera has become available to use.

The default implementation of this method does nothing.

<br />

<br />

| Parameters ||
|---|---|
| `cameraId` | `String`: The unique identifier of the new camera. This value cannot be `null`. <br /> |

### onCameraRemoved

Added in [API level 37](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void onCameraRemoved (String cameraId)
```

A camera device has been physically removed or is no longer available to the system.

This callback is invoked when a previously available camera, such as a removable external camera, is disconnected. The camera ID will no longer be included in the list returned by `https://developer.android.com/reference/android/hardware/camera2/CameraManager#getCameraIdList()` and any attempt to open it will result in an `https://developer.android.com/reference/java/lang/IllegalArgumentException`.

If an application has an active `https://developer.android.com/reference/android/hardware/camera2/CameraDevice` instance for the removed camera that the client did not `https://developer.android.com/reference/android/hardware/camera2/CameraDevice#close()`, then the application will receive a `https://developer.android.com/reference/android/hardware/camera2/CameraDevice.StateCallback#onDisconnected(android.hardware.camera2.CameraDevice)`.

When a camera is removed, `https://developer.android.com/reference/android/hardware/camera2/CameraManager.AvailabilityCallback#onCameraUnavailable(java.lang.String)` will be invoked for the given `cameraId` before this callback is triggered.

<br />

<br />

| Parameters ||
|---|---|
| `cameraId` | `String`: The unique identifier of the camera that has been removed. This value cannot be `null`. <br /> |

### onCameraUnavailable

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void onCameraUnavailable (String cameraId)
```

A previously-available camera has become unavailable for use.

If an application had an active CameraDevice instance for the now-disconnected camera, that application will receive a `https://developer.android.com/reference/android/hardware/camera2/CameraDevice.StateCallback#onDisconnected(android.hardware.camera2.CameraDevice)`.

The default implementation of this method does nothing.

<br />

<br />

| Parameters ||
|---|---|
| `cameraId` | `String`: The unique identifier of the disconnected camera. This value cannot be `null`. <br /> |

### onPhysicalCameraAvailable

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void onPhysicalCameraAvailable (String cameraId, 
                String physicalCameraId)
```

A physical camera has become available for use again.

By default, all of the physical cameras of a logical multi-camera are available, so `https://developer.android.com/reference/android/hardware/camera2/CameraManager.AvailabilityCallback#onPhysicalCameraAvailable(java.lang.String,%20java.lang.String)` is not called for any of the physical cameras of a logical multi-camera, when `https://developer.android.com/reference/android/hardware/camera2/CameraManager.AvailabilityCallback#onCameraAvailable(java.lang.String)` for the logical multi-camera is invoked. However, if some specific physical cameras are unavailable to begin with, `https://developer.android.com/reference/android/hardware/camera2/CameraManager.AvailabilityCallback#onPhysicalCameraUnavailable(java.lang.String,%20java.lang.String)` may be invoked after `https://developer.android.com/reference/android/hardware/camera2/CameraManager.AvailabilityCallback#onCameraAvailable(java.lang.String)`.

If `https://developer.android.com/reference/android/content/pm/ApplicationInfo#targetSdkVersion` \< `https://developer.android.com/reference/android/os/Build.VERSION_CODES#UPSIDE_DOWN_CAKE`, opening a logical camera disables the `https://developer.android.com/reference/android/hardware/camera2/CameraManager.AvailabilityCallback#onPhysicalCameraAvailable(java.lang.String,%20java.lang.String)` and `https://developer.android.com/reference/android/hardware/camera2/CameraManager.AvailabilityCallback#onPhysicalCameraUnavailable(java.lang.String,%20java.lang.String)` callbacks for its physical cameras. For example, if app A opens the camera device:

- All apps subscribing to ActivityCallback get `https://developer.android.com/reference/android/hardware/camera2/CameraManager.AvailabilityCallback#onCameraUnavailable(java.lang.String)`.
- No app (including app A) subscribing to ActivityCallback gets `https://developer.android.com/reference/android/hardware/camera2/CameraManager.AvailabilityCallback#onPhysicalCameraAvailable(java.lang.String,%20java.lang.String)` or `https://developer.android.com/reference/android/hardware/camera2/CameraManager.AvailabilityCallback#onPhysicalCameraUnavailable(java.lang.String,%20java.lang.String)`, because the logical camera is unavailable (some app is using it).

If `https://developer.android.com/reference/android/content/pm/ApplicationInfo#targetSdkVersion` ≥ `https://developer.android.com/reference/android/os/Build.VERSION_CODES#UPSIDE_DOWN_CAKE`:

- A physical camera status change will trigger `https://developer.android.com/reference/android/hardware/camera2/CameraManager.AvailabilityCallback#onPhysicalCameraAvailable(java.lang.String,%20java.lang.String)` or `https://developer.android.com/reference/android/hardware/camera2/CameraManager.AvailabilityCallback#onPhysicalCameraUnavailable(java.lang.String,%20java.lang.String)` even after the logical camera becomes unavailable. A `https://developer.android.com/reference/android/hardware/camera2/CameraManager.AvailabilityCallback#onCameraUnavailable(java.lang.String)` call for a logical camera doesn't reset the physical cameras' availability status. This makes it possible for an application opening the logical camera device to know which physical camera becomes unavailable or available to use.
- Similar to `https://developer.android.com/reference/android/os/Build.VERSION_CODES#TIRAMISU` and earlier, the logical camera's `https://developer.android.com/reference/android/hardware/camera2/CameraManager.AvailabilityCallback#onCameraAvailable(java.lang.String)` callback implies all of its physical cameras' status become available. `https://developer.android.com/reference/android/hardware/camera2/CameraManager.AvailabilityCallback#onPhysicalCameraUnavailable(java.lang.String,%20java.lang.String)` will be called for any unavailable physical cameras upon the logical camera becoming available.

Given the pipeline nature of the camera capture through `https://developer.android.com/reference/android/hardware/camera2/CaptureRequest`, there may be frame drops if the application requests images from a physical camera of a logical multi-camera and that physical camera becomes unavailable. The application should stop requesting directly from an unavailable physical camera as soon as `https://developer.android.com/reference/android/hardware/camera2/CameraManager.AvailabilityCallback#onPhysicalCameraUnavailable(java.lang.String,%20java.lang.String)` is received, and also be ready to robustly handle frame drop errors for requests targeting physical cameras, since those errors may arrive before the unavailability callback.

The default implementation of this method does nothing.

<br />

<br />

| Parameters ||
|---|---|
| `cameraId` | `String`: The unique identifier of the logical multi-camera. This value cannot be `null`. <br /> |
| `physicalCameraId` | `String`: The unique identifier of the physical camera. This value cannot be `null`. <br /> |

**See also:**

- `https://developer.android.com/reference/android/hardware/camera2/CameraManager.AvailabilityCallback#onCameraAvailable(java.lang.String)`
- `https://developer.android.com/reference/android/hardware/camera2/CameraManager.AvailabilityCallback#onPhysicalCameraUnavailable(java.lang.String,%20java.lang.String)`

### onPhysicalCameraUnavailable

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void onPhysicalCameraUnavailable (String cameraId, 
                String physicalCameraId)
```

A previously-available physical camera has become unavailable for use.

By default, all of the physical cameras of a logical multi-camera are unavailable if the logical camera itself is unavailable. No availability callbacks will be called for any of the physical cameras of its parent logical multi-camera, when `https://developer.android.com/reference/android/hardware/camera2/CameraManager.AvailabilityCallback#onCameraUnavailable(java.lang.String)` for the logical multi-camera is invoked.

If `https://developer.android.com/reference/android/content/pm/ApplicationInfo#targetSdkVersion` \< `https://developer.android.com/reference/android/os/Build.VERSION_CODES#UPSIDE_DOWN_CAKE`, opening a logical camera disables the `https://developer.android.com/reference/android/hardware/camera2/CameraManager.AvailabilityCallback#onPhysicalCameraAvailable(java.lang.String,%20java.lang.String)` and `https://developer.android.com/reference/android/hardware/camera2/CameraManager.AvailabilityCallback#onPhysicalCameraUnavailable(java.lang.String,%20java.lang.String)` callbacks for its physical cameras. For example, if app A opens the camera device:

- All apps subscribing to ActivityCallback get `https://developer.android.com/reference/android/hardware/camera2/CameraManager.AvailabilityCallback#onCameraUnavailable(java.lang.String)`.
- No app (including app A) subscribing to ActivityCallback gets `https://developer.android.com/reference/android/hardware/camera2/CameraManager.AvailabilityCallback#onPhysicalCameraAvailable(java.lang.String,%20java.lang.String)` or `https://developer.android.com/reference/android/hardware/camera2/CameraManager.AvailabilityCallback#onPhysicalCameraUnavailable(java.lang.String,%20java.lang.String)`, because the logical camera is unavailable (some app is using it).

If `https://developer.android.com/reference/android/content/pm/ApplicationInfo#targetSdkVersion` ≥ `https://developer.android.com/reference/android/os/Build.VERSION_CODES#UPSIDE_DOWN_CAKE`:

- A physical camera status change will trigger `https://developer.android.com/reference/android/hardware/camera2/CameraManager.AvailabilityCallback#onPhysicalCameraAvailable(java.lang.String,%20java.lang.String)` or `https://developer.android.com/reference/android/hardware/camera2/CameraManager.AvailabilityCallback#onPhysicalCameraUnavailable(java.lang.String,%20java.lang.String)` even after the logical camera becomes unavailable. A `https://developer.android.com/reference/android/hardware/camera2/CameraManager.AvailabilityCallback#onCameraUnavailable(java.lang.String)` call for a logical camera doesn't reset the physical cameras' availability status. This makes it possible for an application opening the logical camera device to know which physical camera becomes unavailable or available to use.
- Similar to `https://developer.android.com/reference/android/os/Build.VERSION_CODES#TIRAMISU` and earlier, the logical camera's `https://developer.android.com/reference/android/hardware/camera2/CameraManager.AvailabilityCallback#onCameraAvailable(java.lang.String)` callback implies all of its physical cameras' status become available. `https://developer.android.com/reference/android/hardware/camera2/CameraManager.AvailabilityCallback#onPhysicalCameraUnavailable(java.lang.String,%20java.lang.String)` will be called for any unavailable physical cameras upon the logical camera becoming available.

Given the pipeline nature of the camera capture through `https://developer.android.com/reference/android/hardware/camera2/CaptureRequest`, there may be frame drops if the application requests images from a physical camera of a logical multi-camera and that physical camera becomes unavailable. The application should stop requesting directly from an unavailable physical camera as soon as `https://developer.android.com/reference/android/hardware/camera2/CameraManager.AvailabilityCallback#onPhysicalCameraUnavailable(java.lang.String,%20java.lang.String)` is received, and also be ready to robustly handle frame drop errors for requests targeting physical cameras, since those errors may arrive before the unavailability callback.

The default implementation of this method does nothing.

<br />

<br />

| Parameters ||
|---|---|
| `cameraId` | `String`: The unique identifier of the logical multi-camera. This value cannot be `null`. <br /> |
| `physicalCameraId` | `String`: The unique identifier of the physical camera. This value cannot be `null`. <br /> |

**See also:**

- `https://developer.android.com/reference/android/hardware/camera2/CameraManager.AvailabilityCallback#onCameraAvailable(java.lang.String)`
- `https://developer.android.com/reference/android/hardware/camera2/CameraManager.AvailabilityCallback#onPhysicalCameraAvailable(java.lang.String,%20java.lang.String)`