ANDROID CAMERA: getParameters failed (empty parame

2020-07-30 00:43发布

问题:

Hi I am getting this issue only in OS versions below lollipop, searched a lot for this bit didn't found the right solution. I think the issue is with OS version Its working fine in 5+ my piece of code is

 private void setCameraPhotoQuality(Camera camera) {
        final Camera.Parameters parameters = camera.getParameters();

        parameters.setPictureFormat(PixelFormat.JPEG);

        if (configurationProvider.getMediaQuality() == Configuration.MEDIA_QUALITY_LOW) {
            parameters.setJpegQuality(50);
        } else if (configurationProvider.getMediaQuality() == Configuration.MEDIA_QUALITY_MEDIUM) {
            parameters.setJpegQuality(75);
        } else if (configurationProvider.getMediaQuality() == Configuration.MEDIA_QUALITY_HIGH) {
            parameters.setJpegQuality(100);
        } else if (configurationProvider.getMediaQuality() == Configuration.MEDIA_QUALITY_HIGHEST) {
            parameters.setJpegQuality(100);
        }
        parameters.setPictureSize(photoSize.getWidth(), photoSize.getHeight());

        camera.setParameters(parameters);
    }

 java.lang.RuntimeException: getParameters failed (empty parameters)
    at android.hardware.Camera.native_getParameters(Native Method)
    at android.hardware.Camera.getParameters(Camera.java:1662)

回答1:

Issue is with emulator, Other than that screen freezing issue is solved by adding

camera.stopPreview();

camera.startPreview();

in surfaceChanged method.