Camera X accessing wide angle camera

4 views
Skip to first unread message

Pratham Kumar Jha

unread,
7:01 AM (5 hours ago) 7:01 AM
to Android CameraX Discussion Group
Hi guys I currently access the wide angle camera on devices using the following method: 

private fun findWideAngleCamera(manager: CameraManager): String? {
        var wideAngleCameraId: String? = null
        var widestFieldOfView = 0f

        try {
            val cameraIds = manager.cameraIdList
            for (cameraId in cameraIds) {
                val characteristics = manager.getCameraCharacteristics(cameraId)

                val lensFacing = characteristics.get(CameraCharacteristics.LENS_FACING)
                val sensorInfo =
                    characteristics.get(CameraCharacteristics.SENSOR_INFO_PHYSICAL_SIZE)
                val focalLengths =
                    characteristics.get(CameraCharacteristics.LENS_INFO_AVAILABLE_FOCAL_LENGTHS)
                val minimumFocusDistance =
                    characteristics.get(CameraCharacteristics.LENS_INFO_MINIMUM_FOCUS_DISTANCE)

                if (lensFacing == CameraCharacteristics.LENS_FACING_BACK &&
                    sensorInfo != null &&
                    focalLengths != null &&
                    minimumFocusDistance != null
                ) {
                    val fieldOfView = calculateFieldOfView(sensorInfo, focalLengths)
                    if (fieldOfView > widestFieldOfView) {
                        widestFieldOfView = fieldOfView
                        wideAngleCameraId = cameraId
                    }
                }
            }
        } catch (e: CameraAccessException) {
            e.printStackTrace()
        }

Now this works on some devices but on others I only get 1 camera in the list even when wide angle camera is present on the device.

1. Any better method to access the wide angle camera on these devices?
2. Could I use the getMinZoomRatio to set zoom below 1 on these devices to use wide angle camera?

Reply all
Reply to author
Forward
0 new messages