Camera autofocus callback not happening

Viewed 8382

I am using the Camera API on the Android and gotten my code to work on several platforms including the Samsung Galaxies and HTC Desire. So far I'm only experiencing a problem on the HTC Desire Z, which is intermittent.

in my code I'm calling the following instructions

camera.startPreview();
camera.autoFocus(autoFocusCallback);

where I have already created the autoFocusCallback class required. I'd like to stress again that this code works on the phones, including the one I'm having problems with, so don't go scrutinizing the code. :) After the callback is called, my code then goes on to take the picture, but that part is irrelevant for now.

The intermittent problem is that for a certain random picture (happens one out of 20-100 times), the callback does not happen. I have verified with my own Log.i()'s that this is the last command performed (i.e. the code does not get to the callback). Debug also shows that no errors are reported.

Just to set your mind at ease, my callback looks something like this

AutoFocusCallback autoFocusCallback = new AutoFocusCallback() {
  @Override
  public void onAutoFocus(boolean success, Camera camera) {
    Log.i("tag","this ran"); 
    ...
    ...
  }
};

The Logcat results for a successful run looks something like this

07-12 10:17:50.564: DEBUG/QualcommCameraHardware(1223): startPreview X
07-12 10:17:50.564: DEBUG/QualcommCameraHardware(1223): autoFocus E
07-12 10:17:50.564: DEBUG/QualcommCameraHardware(1223): autoFocus X
07-12 10:17:50.564: DEBUG/QualcommCameraHardware(1223): runAutoFocus E
07-12 10:17:50.564: DEBUG/QualcommCameraHardware(1223): af start (fd 49)
07-12 10:17:51.184: DEBUG/QualcommCameraHardware(1223): native_set_afmode: ctrlCmd.status == 0
07-12 10:17:51.184: DEBUG/QualcommCameraHardware(1223): af done: 1
07-12 10:17:51.184: DEBUG/QualcommCameraHardware(1223): runAutoFocus X
07-12 10:17:51.184: DEBUG/QualcommCameraHardware(1223): takePicture(479)

But the problematic run is like this

07-12 10:17:52.194: DEBUG/QualcommCameraHardware(1223): startPreview X
07-12 10:17:52.194: DEBUG/QualcommCameraHardware(1223): autoFocus E
07-12 10:17:52.194: DEBUG/QualcommCameraHardware(1223): autoFocus X
07-12 10:17:52.194: DEBUG/QualcommCameraHardware(1223): runAutoFocus E
07-12 10:17:52.194: DEBUG/QualcommCameraHardware(1223): af start (fd 49)

and then it hangs.

I'd like to know if anyone has any ideas about this problem, or if you have experienced something similar? I've only managed to find one thread on the net with similar problems, here it is http://groups.google.com/group/android-developers/browse_thread/thread/75ecb8db0ae02bdb

2 Answers
Related