I have a torch / flashlight app using this code

Turn On

```
    params = camera.getParameters();
    params.setFlashMode(Parameters.FLASH_MODE_TORCH);
    camera.setParameters(params);
    camera.startPreview();

```

Turn Off

```
    params = camera.getParameters();
    params.setFlashMode(Parameters.FLASH_MODE_OFF);
    camera.setParameters(params);
    camera.stopPreview();

```

However now 

> 
> **android.hardware.Camera** has been deprecated and It is advised to use the new **camera2** api instead.
> 
> 
> 

Any help on how I would use `camera2` to turn on/off the device's flashlight? 

Thank you for your help