I have downloaded and changed Google's Camera 2 Basic example. My changes add iterating through camera devices and showing some of their characteristics. I created this function:
private void printCameraCharacteristics() {
Log.d(TAG, "printCameraCharacteristics");
Activity activity = getActivity();
CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE);
try {
for (String cameraId : manager.getCameraIdList()) {
Log.d(TAG, "------------------------------ "+ cameraId +" ----------------------------------");
CameraCharacteristics characteristics
= manager.getCameraCharacteristics(cameraId);
// Examine the LENS_FACING characteristic
Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING);
if(facing == null){
Log.d(TAG, "Facing: NULL");
}
else if(facing == CameraCharacteristics.LENS_FACING_BACK){
Log.d(TAG, "Facing: BACK");
} else if(facing == CameraCharacteristics.LENS_FACING_FRONT){
Log.d(TAG, "Facing: FRONT");
} else if(facing == CameraCharacteristics.LENS_FACING_EXTERNAL){
Log.d(TAG, "Facing: EXTERNAL");
} else {
Log.d(TAG, "Facing: UNKNOWN");
}
// Check if the flash is supported.
Boolean available = characteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE);
if(available == null){
Log.d(TAG, "Flash unknown");
}
else if(available){
Log.d(TAG, "Flash supported");
} else {
Log.d(TAG, "Flash unsupported");
}
// Check how much the zoom is supported
Float zoom = characteristics.get(CameraCharacteristics.SCALER_AVAILABLE_MAX_DIGITAL_ZOOM);
Log.d(TAG, "Max supported digital zoom: " + zoom);
// Write all the available focal lengths
float[] focalLengths = characteristics.get(CameraCharacteristics.LENS_INFO_AVAILABLE_FOCAL_LENGTHS);
Log.d(TAG, "Available focal lengths: " + Arrays.toString(focalLengths));
// Check the distortion
if (Build.VERSION.SDK_INT >= 23) {
float[] lensDistortionCoefficients = characteristics.get(CameraCharacteristics.LENS_RADIAL_DISTORTION);
Log.d(TAG, "Lens distortion coefficients : " + Arrays.toString(lensDistortionCoefficients));
}
Log.d(TAG, "----------------------------------------------------------------");
}
} catch (CameraAccessException e) {
Log.d(TAG, "CameraAccessException: " + e.getMessage());
} catch (NullPointerException e) {
Log.d(TAG, "NullPointerException: " + e.getMessage());
}
}
And I just added it to the example by changing onCreateView
:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
printCameraCharacteristics();
return inflater.inflate(R.layout.fragment_camera2_basic, container, false);
}
And I got the following output for Huawei P30 Pro:
D/Camera2BasicFragment: ------------------------------ 0 ----------------------------------
D/Camera2BasicFragment: Facing: BACK
Flash supported
Max supported digital zoom: 10.0
D/Camera2BasicFragment: Available focal lengths: [5.56]
Lens distortion coefficients : [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
----------------------------------------------------------------
------------------------------ 1 ----------------------------------
Facing: FRONT
Flash unsupported
Max supported digital zoom: 6.0
Available focal lengths: [3.36]
Lens distortion coefficients : [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
----------------------------------------------------------------
D/Camera2BasicFragment: ------------------------------ 2 ----------------------------------
Facing: BACK
Flash unsupported
Max supported digital zoom: 10.0
Available focal lengths: [5.56]
Lens distortion coefficients : [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
----------------------------------------------------------------
------------------------------ 3 ----------------------------------
D/Camera2BasicFragment: Facing: BACK
Flash unsupported
Max supported digital zoom: 10.0
Available focal lengths: [2.35]
Lens distortion coefficients : [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
----------------------------------------------------------------
------------------------------ 4 ----------------------------------
Facing: BACK
Flash unsupported
Max supported digital zoom: 10.0
Available focal lengths: [14.46]
D/Camera2BasicFragment: Lens distortion coefficients : [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
----------------------------------------------------------------
However, some of the output seems inconsistent. P30 Pro has one camera with 5x zoom and the documentation says that the get for the LENS_INFO_AVAILABLE_FOCAL_LENGTHS
parameter will return an array longer than 1 for a camera that supports optical zoom. Huawei P30 Pro also has an ultrawide camera and, from my understanding, the LENS_RADIAL_DISTORTION
should return some other parameters than 0
.
I have tested this example with Xiaomi Mi 9, which has 4 cameras, and I only get 2.
My question is: what is going on here? Why am I getting all this data that is inconsistent with what should be shown? Is my understanding of what should be shown, and thus my example, wrong?