0
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.

  • Does this answer your question? [Unfortunately MyApp has stopped. How can I solve this?](https://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this) – Markus Kauppinen Jan 22 '20 at 18:14
  • 2
    What do you mean with "my app does not open"? Does it crash? If so, please add the stacktrace to your question. – Giorgos Neokleous Jan 22 '20 at 18:16

0 Answers0