AvailabilityCallback
abstract class AvailabilityCallback
kotlin.Any | |
↳ | android.hardware.camera2.CameraManager.AvailabilityCallback |
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 android.hardware.camera2.CameraManager#registerAvailabilityCallback to be notified of such availability changes.
Summary
Public constructors | |
---|---|
Public methods | |
---|---|
open Unit |
Called whenever camera access priorities change. |
open Unit |
onCameraAvailable(cameraId: String) A new camera has become available to use. |
open Unit |
A previously-available camera has become unavailable for use. |
open Unit |
onPhysicalCameraAvailable(cameraId: String, physicalCameraId: String) A physical camera has become available for use again. |
open Unit |
A previously-available physical camera has become unavailable for use. |
Public constructors
AvailabilityCallback
AvailabilityCallback()
Public methods
onCameraAccessPrioritiesChanged
open fun onCameraAccessPrioritiesChanged(): Unit
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.
onCameraAvailable
open fun onCameraAvailable(cameraId: String): Unit
A new camera has become available to use.
The default implementation of this method does nothing.
Parameters | |
---|---|
cameraId |
String: The unique identifier of the new camera. This value cannot be null . |
onCameraUnavailable
open fun onCameraUnavailable(: String): Unit
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 disconnection error
.
The default implementation of this method does nothing.
Parameters | |
---|---|
cameraId |
String: The unique identifier of the disconnected camera. This value cannot be null . |
onPhysicalCameraAvailable
open fun onPhysicalCameraAvailable(
cameraId: String,
physicalCameraId: String
): Unit
A physical camera has become available for use again.
By default, all of the physical cameras of a logical multi-camera are available, so onPhysicalCameraAvailable
is not called for any of the physical cameras of a logical multi-camera, when onCameraAvailable
for the logical multi-camera is invoked. However, if some specific physical cameras are unavailable to begin with, onPhysicalCameraUnavailable
may be invoked after onCameraAvailable
.
If targetSdkVersion
< android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE
, opening a logical camera disables the onPhysicalCameraAvailable
and onPhysicalCameraUnavailable
callbacks for its physical cameras. For example, if app A opens the camera device:
- All apps subscribing to ActivityCallback get
onCameraUnavailable
. - No app (including app A) subscribing to ActivityCallback gets
onPhysicalCameraAvailable
oronPhysicalCameraUnavailable
, because the logical camera is unavailable (some app is using it).
If targetSdkVersion
≥ android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE
:
- A physical camera status change will trigger
onPhysicalCameraAvailable
oronPhysicalCameraUnavailable
even after the logical camera becomes unavailable. AonCameraUnavailable
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
Android 13
and earlier, the logical camera'sonCameraAvailable
callback implies all of its physical cameras' status become available.onPhysicalCameraUnavailable
will be called for any unavailable physical cameras upon the logical camera becoming available.
Given the pipeline nature of the camera capture through , 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 onPhysicalCameraUnavailable
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.
Parameters | |
---|---|
cameraId |
String: The unique identifier of the logical multi-camera. This value cannot be null . |
physicalCameraId |
String: The unique identifier of the physical camera. This value cannot be null . |
onPhysicalCameraUnavailable
open fun onPhysicalCameraUnavailable(
: String,
: String
): Unit
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 onCameraUnavailable
for the logical multi-camera is invoked.
If targetSdkVersion
< android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE
, opening a logical camera disables the onPhysicalCameraAvailable
and onPhysicalCameraUnavailable
callbacks for its physical cameras. For example, if app A opens the camera device:
- All apps subscribing to ActivityCallback get
onCameraUnavailable
. - No app (including app A) subscribing to ActivityCallback gets
onPhysicalCameraAvailable
oronPhysicalCameraUnavailable
, because the logical camera is unavailable (some app is using it).
If targetSdkVersion
≥ android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE
:
- A physical camera status change will trigger
onPhysicalCameraAvailable
oronPhysicalCameraUnavailable
even after the logical camera becomes unavailable. AonCameraUnavailable
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
Android 13
and earlier, the logical camera'sonCameraAvailable
callback implies all of its physical cameras' status become available.onPhysicalCameraUnavailable
will be called for any unavailable physical cameras upon the logical camera becoming available.
Given the pipeline nature of the camera capture through , 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 onPhysicalCameraUnavailable
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.
Parameters | |
---|---|
cameraId |
String: The unique identifier of the logical multi-camera. This value cannot be null . |
physicalCameraId |
String: The unique identifier of the physical camera. This value cannot be null . |