get Best Focus Mode for Camera - Android android.hardware

Android examples for android.hardware:Camera Focus

Description

get Best Focus Mode for Camera

Demo Code

import java.util.List;

import android.hardware.Camera;
import android.os.Build;

public class Main {

  public static String getBestFocusMode(Camera.Parameters params) {
    if (params == null)
      return null;

    String focusMode = null;/*from  w ww .j  a v  a2 s  .c  om*/

    List<String> focusModes = params.getSupportedFocusModes();

    if (Build.VERSION.SDK_INT >= 14 && focusModes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) {
      params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
    } else if (Build.VERSION.SDK_INT >= 9 && focusModes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO)) {
      params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);
    } else if (focusModes.contains(Camera.Parameters.FOCUS_MODE_AUTO)) {
      params.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
    }

    return focusMode;
  }

}

Related Tutorials