在 Android Lollipop 版本上关闭手电筒

Turn off Flashlight on Android Lollipop version

kCamera = Camera.open();
kCamera.Parameters cam1= k.Camera.getParameters();
cam1.setFlashMode(Parameters.FLASH_MODE_TORCH);
kCamera.setParameters(cam1);
SurfaceTexture mPreviewTexture = new SurfaceTexture(0);
try {
     kCamera.setPreviewTexture(mPreviewTexture);
} catch {
}
mCam.startPreview();

这很好用,它打开了手电筒。

但是我怎样才能关闭呢?

来自documentation:

public static final String FLASH_MODE_OFF

Added in API level 5 Flash will not be fired.

Constant Value: "off"

所以,你可以这样定义函数:

public void turnOffFlashLight(Camera camera){
        Camera.Parameters cam1 = camera.getParameters();
        cam1.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
        kCamera.setParameters(cam1);
    }

然后,在需要的时候使用它:

turnOffFlashLight(kCamera);