Search code examples
javaandroidandroid-cameraandroid-camera2

Camera2 getCameraCharacteristics Returning Problematic Values


I have a problem with a code snippet that I added to the end of the createCameraPreviewSession function of the Camera2Basic example code.

I have the following snippet that prints the camera characteristics to the console:

CameraManager manager = (CameraManager) getContext().getSystemService(Context.CAMERA_SERVICE);
CameraCharacteristics characteristics = manager.getCameraCharacteristics(mCameraId);
List<CameraCharacteristics.Key<?>> keys = characteristics.getKeys();
for (CameraCharacteristics.Key key: keys){
    //Log.i(key.getName(), (String)characteristics.get(key));
    //Log.i("hello", "there");
    System.out.println("Key: " + key + "- " + key.getName() + "; Value: " + characteristics.get(key));
}

and for the most part it returns good values:

Key: android.sensor.info.pixelArraySize; Value: 4128x3096

But for many values the result is neither reasonable nor null, but appears to have some encoding issue:

Key: android.control.aeAvailableModes; Value: [I@829b672

I've tried testing for and omitting null values and re-casting to String. Ideally I need to print out the full set of values legibly, or test whether the value is relevant rather than getting garbage values in the list.


Solution

  • The CONTROL_AE_AVAILABLE_MODES entry is an integer array (int[]). If you call toString on it, you get the default Java output for an array's toString() call. See How do I print my Java object without getting "SomeType@2f92e0f4"? for details of that.

    You can use Arrays.toString() instead to get the output you likely want ("[1,3,5,3]" I assume), but you'll have to hard-code which keys to use it on.