I’m using the Motorola Droid X and for some reason the success variable for success in the onAutoFocus(boolean success, Camera camera) always returns false. It seems to work with other devices including a Droid 2 so it’s seems to be a device specific problem.
My code is basically this:
camera.autoFocus(new AutoFocusCallback() {
@Override
public void onAutoFocus(boolean success, Camera camera) {
takePicture();
}
});
After hours of debugging, the problem was setting the preview size of the surface view to a large size. I don’t understand why that would affect the autofocus but setting the preview size to a smaller size fixed the problem. It might be caused by the preview size being larger than the screen resolution because that was the only resolution that didn’t work. Hope this helps anyone else who might run into this problem.
Update:
I ran into this problem again after changing the layout of my preview page and it seems like the focus just fails for certain preview sizes. So far these sizes failed for me: 720×480, 1280×720