To use both cameras simultaneously, you need to use the Concurrent Camera API introduced in CameraX 1.3.0. The error "Open count: 1 (Max allowed: 1)" occurs because CameraX defaults to a single active camera unless you explicitly bind multiple cameras together in a single coordinated call.
Instead of calling bindToLifecycle twice, you must use the call that accepts a list of SingleCameraConfig objects. Please see Concurrent camera sample /
ConcurrentCamera | API
Here is a quick code snippet based on our integration logic to get you started:
val cameraProvider = ProcessCameraProvider.getInstance(context).await()
// 1. Check for available concurrent camera selectors
val concurrentCameraInfos = cameraProvider.availableConcurrentCameraInfos
if (concurrentCameraInfos.isEmpty()) {
// Device does not support concurrent camera
return
}
// 2. Select the first available pair (typically Front + Back)
val selectorPair = concurrentCameraInfos[0]
val primarySelector = selectorPair[0].cameraSelector
val secondarySelector = selectorPair[1].cameraSelector
// 3. Define configurations for each camera
val primaryConfig = SingleCameraConfig(
primarySelector,
UseCaseGroup.Builder()
.addUseCase(preview0)
.addUseCase(imageAnalysis0) // Your Analyzer goes here
.build(),
lifecycleOwner
)
val secondaryConfig = SingleCameraConfig(
secondarySelector,
UseCaseGroup.Builder()
.addUseCase(preview1)
.addUseCase(imageAnalysis1)
.build(),
lifecycleOwner
)
// 4. Bind both in a single call
val concurrentCamera = cameraProvider.bindToLifecycle(listOf(primaryConfig, secondaryConfig))