Reputation: 6834
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);
Upvotes: 1
Views: 972
Reputation: 11
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);
Upvotes: 1