如何设置对焦?这也是有技巧的。代码如下:
private static boolean setCameraFocus(Camera.Parameters parameters, String selected) { List<String> modes = parameters.getSupportedFocusModes(); try { for (String mode : modes) { //优先使用这个对焦方式。 if (null != mode && mode.equals(selected)) { parameters.setFocusMode(mode); return true; } } } catch (Exception e) { e.printStackTrace(); } return false; } private static void setCameraFocus(Camera.Parameters parameters) { String[] selectedModes = { Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO, Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE }; for (String mode : selectedModes) { if (setCameraFocus(parameters, mode)) { return; } } }