kos kos - 2 months ago 22
Android Question

Android auto focus when continuous auto focus modes are not supported

I have a camera inside the app and I want to make it auto focus continuously in the same way that the phone's camera does it. I found the modes

, but they are not supported by some of the HTC Gingerbread phones I'm testing on.

This is what I'm doing to determine whether I can use these modes:

Camera.Parameters parameters = mCamera.getParameters();
List<String> supportedFocusModes = parameters.getSupportedFocusModes();

supportedFocusModes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) {
else if (supportedFocusModes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO)) {
else if (supportedFocusModes.contains(Camera.Parameters.FOCUS_MODE_AUTO)) {
// auto focus on request only

Running on several different Gingerbread HTC phones, I don't get the continuous modes back, but I get "auto". Which lets me auto focus on demand (when I call
, but the camera will not refocus if the user moves the camera.

I cannot set the focus mode to anything the camera does not support, if I do it shows up blank.

One solution that I tried is to call
on a timer. But this causes the camera to refocus continuously, even if it is already in focus.

Is there a way to implement a continuous auto focus experience on these phones? When I look at HTCs camera app on these phones, it does have continuous auto focus - as you move around the camera refocuses and does not keep refocusing once the picture is in focus.

kos kos

We had a requirement to support a very wide range of phones. So my solution in the end was to handle each case differently.

For the scenario of phones without continuous auto-focus support, I implemented a utility to listen to the accelerometer using SensorManager and trigger mCamera.autoFocus(...) whenever the user moves the camera.

There were also some older tablets that only supported fixed focus (who would use such a thing!), in that case the picture needed to be taken immediately - not on the focus callback.

And for most modern phones, the code snippet above was fine to use FOCUS_MODE_CONTINUOUS_PICTURE.