Q:

How to check when camera autofocus is done android?

I would like to know if there is a way to know when the autofocus is done?
I have a app that doing some  image processing on video. My first thing that I need to do is to turn on the flash and the autofocus, my problem is that I don't know if the autofocus is done or not (I need to know it programmatically) so I can start all the image processing only after the auto focus is done.
This is how I configure the camera settings :
@Override
public void surfaceCreated(SurfaceHolder arg0) {
 try {
    camera = Camera.open();

    parameters = camera.getParameters();
    parameters.setFlashMode(Parameters.FLASH_MODE_TORCH);
    parameters.setFocusMode(Parameters.FOCUS_MODE_AUTO);
    camera.setParameters(parameters);
    camera.setPreviewDisplay(holder);
    camera.startPreview();

    recorder = new MediaRecorder();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

I just want to be clear, everything is working good, I just want to know when exactly the autofocus is done.
Thanks!

A:

You have to check it first that a camera supports autofocus or not. Check it like this way and you can also check if your phone supports flash light or not follow this link How turn on camera flash light programmatically in Android?
PackageManager pm = getPackageManager();
if(pm.hasSystemFeature(PackageManager.FEATURE_CAMERA) && pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_AUTOFOCUS)){
       // True means the camera has autofocus mode on. Do what ever you want to do 
}

A:

Ok, I found the answer for this, I don't know why I don't think about it before.
This is the new code :
@Override
public void surfaceCreated(SurfaceHolder arg0) {
 try {
    camera = Camera.open();

    parameters = camera.getParameters();
    parameters.setFlashMode(Parameters.FLASH_MODE_TORCH);
    parameters.setFocusMode(Parameters.FOCUS_MODE_AUTO);
    camera.setParameters(parameters);
    camera.setPreviewDisplay(holder);
    camera.startPreview();
    camera.autoFocus(new AutoFocusCallback() {

        @Override
        public void onAutoFocus(boolean success, Camera camera) {

        }
    });
    recorder = new MediaRecorder();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

