2

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)
Uma Achanta
  • 3,669
  • 4
  • 22
  • 49
  • 1
    Possible duplicate of [Correct handling of exception: "getParameters failed (empty parameters)"](https://stackoverflow.com/questions/14941625/correct-handling-of-exception-getparameters-failed-empty-parameters) – sdabet Jun 16 '17 at 09:51
  • I've checked it already. It is not working for me @ fiddler – Uma Achanta Jun 16 '17 at 09:53
  • 1
    I am pretty sure your problem is same as in *[Correct handling of exception: "getParameters failed (empty parameters)](https://stackoverflow.com/questions/14941625/correct-handling-of-exception-getparameters-failed-empty-parameters)*. The question is, why the camera is in a bad state. And more, why the camera is in a bad state on KitKat but not on Lollipop. To help the community help you, please explain how and when this `setCameraPhotoQuality()` method is called. – Alex Cohn Jun 19 '17 at 08:24
  • thanks@ fiddler, Alex. My problem is with the emulator. Its working in some emulators and freezing in some emulators. Got solution and posting it below. – Uma Achanta Jun 20 '17 at 05:45
  • In my case, I was getting this on the stock Camera app on an Android API 22 emulator. I fixed it by using the 32bit x86 OS image on the emulator instead of the 64bit x86 one. – Joshua Pinter Oct 30 '17 at 02:34
  • @JoshuaPinter, I also got this exception on API 23 emulator. When opened camera it showed a buggy picture (colored animated stripes of random colors) and sometimes crashed. – CoolMind Feb 10 '19 at 21:50

1 Answers1

0

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

camera.stopPreview();

camera.startPreview();

in surfaceChanged method.

Uma Achanta
  • 3,669
  • 4
  • 22
  • 49
  • 1
    _"Issue is with emulator"_ <-- Any solution for this? My stock emulator Camera app is crashing with this error message... – Joshua Pinter Oct 30 '17 at 01:20
  • Just a quick follow-up: In my case, I was getting this on the stock Camera app on an Android API 22 emulator. I fixed it by using the 32bit x86 OS image on the emulator instead of the 64bit x86 one. – Joshua Pinter Oct 30 '17 at 02:34