打开
手电筒灯的最简单方法是:
Camera camera = Camera.open();
Camera.Parameters parameters = camera.getParameters();
parameters.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
camera.setParameters(parameters);
camera.startPreview();
关闭它的最简单方法是:
Camera camera = Camera.open();
Camera.Parameters parameters = camera.getParameters();
parameters.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
camera.setParameters(parameters);
camera.stopPreview();
但是,由于 Camera 类现已弃用,使用 Camera2 类实现相同结果的最简单方法是什么?我只找到了漫长而复杂的解决方案...
在这里
查看Daniel Netzer的答案你只需要写3行打开手电筒
CameraManager camManager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);
String cameraId = camManager.getCameraIdList()[0]; // Usually front camera is at 0 position and back camera is 1.
camManager.setTorchMode(cameraId, true);