I want to get a specific camera id from multi camera device:
private fun setupCamera() {
val cameraIds: Array<String> = cameraManager.cameraIdList
for (id in cameraIds) {
val cameraCharacteristics = cameraManager.getCameraCharacteristics(id)
if (cameraCharacteristics.get(CameraCharacteristics.LENS_FACING) == CameraCharacteristics.LENS_FACING_FRONT) {
continue
}
val streamConfigurationMap: StreamConfigurationMap? =
cameraCharacteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP)
if (streamConfigurationMap != null) {
previewSize =
cameraCharacteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP)!!
.getOutputSizes(ImageFormat.JPEG).maxByOrNull { it.height * it.width }!!
imageReader = ImageReader.newInstance(
previewSize.width, previewSize.height, ImageFormat.JPEG, 1
)
initPreview()
imageReader.setOnImageAvailableListener(onImageAvailableListener, backgroundHandler)
}
cameraId = id
}
}
I used this code, but it returns just a ultra wide rear camera of device. How can I select which camera that I want?
you can use Jetpack CameraX lib: https://developer.android.google.cn/jetpack/androidx/releases/camera
https://developer.android.google.cn/training/camerax
https://developers.google.cn/codelabs/camerax-getting-started