Actually here's the code.
public class CameraActivity extends Activity implements Camera.FaceDetectionListener, View.OnClickListener { private Camera mCamera; private CameraPreview mPreview; private SurfaceView face; private Button push_btn; private Button btn1; private ImageView faces; static public TextView info; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_camera); mCamera = getCameraInstance(); mPreview = new CameraPreview(this, mCamera); FrameLayout preview = (FrameLayout) findViewById(R.id.camera_frame); info = (TextView) findViewById(R.id.info); push_btn = (Button) findViewById(R.id.push_btn); push_btn.setOnClickListener(this); btn1 = (Button) findViewById(R.id.btn1); btn1.setOnClickListener(this); preview.addView(mPreview); } private static Camera openFrontFacingCamera() { int cameraCount = 0; Camera cam = null; Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); cameraCount = Camera.getNumberOfCameras(); for ( int camIdx = 0; camIdx < cameraCount; camIdx++ ) { Camera.getCameraInfo( camIdx, cameraInfo ); if ( cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT ) { try { cam = Camera.open( camIdx ); } catch (RuntimeException e) { Log.e("ex", "Camera failed to open: " + e.getLocalizedMessage()); } } } return cam; } public void onFaceDetection(Camera.Face[] faces, Camera camera) { if (faces.length > 0){ Log.d("MyTag", "here is a face"); } } public static Camera getCameraInstance() { Camera c = null; try { // c = Camera.open(); c = openFrontFacingCamera(); } catch (Exception e){ } return c; } public void onClick(View view) { switch (view.getId()) { case R.id.push_btn: Log.d("MyLog", "making photo..."); mCamera.takePicture(null, null, jpegCallback); Log.d("MyLog", "making photo... OK"); break; case R.id.btn1: Log.d("MyLog", "detecting face..."); mCamera.setFaceDetectionListener(this); mCamera.startFaceDetection(); Log.d("MyLog", "was started"); } } PictureCallback jpegCallback = new PictureCallback() { public void onPictureTaken(byte[] data, Camera camera) { info.setText("ready"); Intent intent = new Intent(CameraActivity.this, Filters.class); info.setText(Integer.toString(mCamera.getParameters().getMaxNumDetectedFaces())); intent.putExtra("BitmapImage", data); startActivity(intent); finish(); } }; } What could be the problem? It would seem that the standard use of the function is exactly following the documentation. In addition, if you take a picture and find a face on it using the media.Face library, then it is located without any problems. Or have they stopped supporting the hardware.camera library in the new firmware and need to write a separate case using the functions from hardware.camera2?
Android 5.1.