I also experienced the same problems.
The Galaxy S5 and perhaps other devices do not seem to have reliable continuous focus behavior. This is very unpleasant as a developer, when the code works fine on most devices, but then comes S5 (a very popular device), and we look pretty bad.
After a big head scratch, I think I have a solution (a more workaround) that works well.
- set the camera to FOCUS_MODE_CONTINUOUS_PICTURE
- in the gesture handler to take a photo (for example, pressing a button, touch event), switch the camera to FOCUS_MODE_AUTO, then release Camera.autoFocus () in deferred mode
This provides a nice, consistent UI focus while previewing photos, but makes the image 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 try and report your results
source share