I am trying to programmatically check whether the Android Smartphone has the macro camera or not.
Tried CameraManager
and through that found the different characteristics of the camera. Than found the specific thresholds of the macro camera and placed the conditions on the characteristics to find the availability of the macro camera in the android smartphone. As there is not direct way as far as I searched to find the macro camera.
val cameraManager = context?.getSystemService(Context.CAMERA_SERVICE) as? CameraManager
cameraManager?.cameraIdList?.forEach { cameraId ->
val characteristics = cameraManager.getCameraCharacteristics(cameraId)
val lensFacing = characteristics.get(CameraCharacteristics.LENS_FACING)
val capabilities =
characteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL)
capabilities?.let {
Log.d("macroCameraLog_2", "isMacroCameraSupported: CAMERA_ID $cameraId")
Log.d("macroCameraLog_2", "isMacroCameraSupported: HARD_WARE_LEVEL $it")
if (it >= CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_3) {
Log.d("macroCameraLog_2", "isMacroCameraSupported: TRUE")
}
}
val afModes = characteristics.get(CameraCharacteristics.CONTROL_AF_AVAILABLE_MODES)
afModes?.let { modes ->
Log.d("macroCameraLog_3", "isMacroCameraSupported: CAMERA_ID $cameraId")
Log.d(
"macroCameraLog_3",
"isMacroCameraSupported: MODES ${formatCharacteristicValue(modes)}"
)
if (modes.contains(CameraMetadata.CONTROL_AF_MODE_MACRO)) {
Log.d("macroCameraLog_3", "Macro AF mode is supported")
}
if (modes.contains(CameraMetadata.CONTROL_AF_MODE_CONTINUOUS_PICTURE)) {
Log.d("macroCameraLog_3", "CONTROL_Macro AF mode is supported")
}
}
if (lensFacing == CameraCharacteristics.LENS_FACING_BACK) {
// Get the minimum focus distance
val minFocusDistance =
characteristics.get(CameraCharacteristics.LENS_INFO_MINIMUM_FOCUS_DISTANCE)
?: return false
Log.d(
"macroCameraLog",
"isMacroCameraSupported: Min_Focus -> $minFocusDistance"
)
Log.d("macroCameraLog", "isMacroCameraSupported: Camera_ID -> $cameraId")
// Define a threshold for macro capability (e.g., less than or equal to 0.05 meters or 5 cm)
if (minFocusDistance in 0.01..0.05) {
Log.d(
"macroCameraLog",
"isMacroCameraSupported: Min_Focus -> $minFocusDistance"
)
Log.d("macroCameraLog", "isMacroCameraSupported: Camera_ID -> $cameraId")
}
}
// Check if it's a rear camera
if (lensFacing == CameraCharacteristics.LENS_FACING_BACK) {
// Check for physical cameras in a multi-camera system
val physicalCameraIds = characteristics.physicalCameraIds
if (physicalCameraIds.isNotEmpty()) {
for (physicalCameraId in physicalCameraIds) {
val physicalCharacteristics =
cameraManager.getCameraCharacteristics(physicalCameraId)
val physicalFocalLengths =
physicalCharacteristics.get(CameraCharacteristics.LENS_INFO_AVAILABLE_FOCAL_LENGTHS)
val minFocusDistance =
physicalCharacteristics.get(CameraCharacteristics.LENS_INFO_MINIMUM_FOCUS_DISTANCE)
?: return false
// Define a threshold for macro capability (e.g., less than or equal to 0.05 meters or 5 cm)
Log.d(
"macroCameraLog",
"Physical_isMacroCameraSupported: Camera_ID -> $cameraId"
)
Log.d(
"macroCameraLog",
"Physical_isMacroCameraSupported: Min_Focus -> $minFocusDistance"
)
if (minFocusDistance in 0.01..0.05) {
Log.d(
"macroCameraLog",
"Physical_isMacroCameraSupported: Min_Focus -> $minFocusDistance"
)
Log.d(
"macroCameraLog",
"Physical_isMacroCameraSupported: Camera_ID -> $cameraId"
)
}
physicalFocalLengths?.let { focalLengths ->
for (focalLength in focalLengths) {
// Check for macro lens characteristics
if (focalLength in 1.0..2.0) {
// Macro lens found in a multi-camera system
// return true
}
}
}
}
}
}
}
The only possible solution I came up with the various properties of the macro camera to be checked according to the specific thresholds like the focal length, hardware level, minimum focus distance and autofocus mode. But I didn’t found any solid solution for checking that the device have the macro camera or not.
You need to sign in to view this answers