CameraManager cameraManager = (CameraManager) getSystemService(CAMERA_SERVICE);
@NonNull
public Size getResolution(@NonNull final CameraManager cameraManager, @NonNull final String cameraId) throws CameraAccessException
{
final CameraCharacteristics characteristics = cameraManager.getCameraCharacteristics(cameraId);
final StreamConfigurationMap map = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
if (map == null)
{
throw new IllegalStateException("Failed to get configuration map.");
}
final Size[] choices = map.getOutputSizes(ImageFormat.JPEG);
Arrays.sort(choices, Collections.reverseOrder(new Comparator<Size>()
{
@Override
public int compare(@NonNull final Size lhs, @NonNull final Size rhs)
{
// Cast to ensure the multiplications won't overflow
return Long.signum((lhs.getWidth() * (long)lhs.getHeight()) - (rhs.getWidth() * (long)rhs.getHeight()));
}
}));
final Size size = getResolution(cameraManager, cameraId);
final float megapixels = (((size.getWidth() * size.getHeight()) / 1000.0f) / 1000.0f);
final String caption = String.format(Locale.getDefault(), "%.1f", megapixels);
textView.setText(caption);
return choices[0];
}
I just want that my app on a TextView shows the resolution of all the devices cameras. I have tried different things, but none of them work.