Find out the ID of the camera that supports flash on Android.

公開日: 2021年02月26日最終更新日: 2022年01月28日

When I wanted to use only the flash light of a camera on Android, I wanted to get the CameraId of the camera that supports flash light at some point before onTorchModeChanged.

I guess I should look at CameraCharacteristics.FLASH_INFO_AVAILABLE.

cameraManager = context.getSystemService(Context.CAMERA_SERVICE) as CameraManager
val cameraIds: Array<String> = cameraManager.cameraIdList
for (id in cameraIds) {
    val info: CameraCharacteristics = cameraManager.getCameraCharacteristics(id)
    if (info.get(CameraCharacteristics.FLASH_INFO_AVAILABLE) as Boolean) {
        cameraID = id
        Log.d("Flashlight", "camera ID: $cameraID")