Current Android devices can have two or more cameras in the front, in the back, or both. That can be a lot of lenses to choose from.
Note: This page uses camera2 classes. We recommend using the CameraX Jetpack library except when your use case requires access to specific features available only in Camera2. Both CameraX and Camera2 work on Android 5.0 (API level 21) and higher.
To accommodate all device configurations, check the camera list and camera characteristics:
val cameraIdList = cameraManager.cameraIdList // may be empty
val characteristics = cameraManager.getCameraCharacteristics(cameraId)
val cameraLensFacing = characteristics.get(CameraCharacteristics.LENS_FACING)
val cameraCapabilities = characteristics.get(CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES)
val cameraCompatible = cameraCapabilities?.contains(
CameraMetadata.REQUEST_AVAILABLE_CAPABILITIES_BACKWARD_COMPATIBLE) ?: false
The variable cameraLensFacing
will be one of: