I\'m working on an Android app that uses the camera to preview and take pictures. I use FOCUS_MODE_CONTINUOUS_PICTURE
with the galaxy S4 and find that the focus
I too have experienced these same issues.
The Galaxy S5, and possibly other devices, don't seem to have reliable behavior in continuous picture focus mode. This is very frustrating as a developer, when code works perfectly on most devices, but then along comes the S5 (a very popular device) and we look pretty bad.
After much head scratching, I think I have a solution (more of a workaround) that is working well.
this provides the nice continuous focus UI during photo preview, but takes the picture in reliable auto-focus mode.
Here is the code:
protected void onTakePicture()
{
// mCamera is the Camera object
// mAutoFocusCallback is a Camera.AutoFocusCallback handler
try
{
// determine current focus mode
Camera.Parameters params = mCamera.getParameters();
if (params.getFocusMode().equals(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE))
{
mCamera.cancelAutoFocus(); // cancels continuous focus
List<String> lModes = params.getSupportedFocusModes();
if (lModes != null)
{
if (lModes.contains(Camera.Parameters.FOCUS_MODE_AUTO))
{
params.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO); // auto-focus mode if supported
mCamera.setParameters(params); // set parameters on device
}
}
// start an auto-focus after a slight (100ms) delay
new Handler().postDelayed(new Runnable() {
public void run()
{
mCamera.autoFocus(mAutoFocusCallback); // auto-focus now
}
}, 100);
return;
}
mCamera.autoFocus(mAutoFocusCallback); // do the focus, callback is mAutoFocusCallback
}
catch (Exception e)
{
Log.e("myApp", e.getMessage());
}
}
please give this a try and report back your results