1

Auto Focus Mode not works in Camera. I have followed some answers One, Two, implemented same as here but not works.

Any hint why its not working!

Code snippet

    Camera.Parameters parameters = mCamera.getParameters();
    List<String> focusModes = parameters.getSupportedFocusModes();
    if(focusModes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)){
        parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
    } else
    if(focusModes.contains(Camera.Parameters.FOCUS_MODE_AUTO)){
        parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
    }

 mCamera.setParameters(parameters);

 mCamera.setPreviewTexture(surface);
 mCamera.startPreview();
 mCamera.autoFocus(autoFocusCallback);
Community
  • 1
  • 1
Kishore Jethava
  • 6,666
  • 5
  • 35
  • 51

1 Answers1

1

I had the same problem, my mobile camera also didn't focus well then I wrote below code and it worked for me. Hopefully, it will help you.

try {
    camera = Camera.open();
} catch (RuntimeException e) {
    e.printStackTrace();
}

parameter = camera.getParameters();
parameter.setPreviewFrameRate(20);
parameter.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
camera.setParameters(parameter);
Søren
  • 6,517
  • 6
  • 43
  • 47