title: Flashlight control in Marshmallow
body: <p>I have a problem regarding the camera in the most recent Marshmallow build, more specifically the flashlight.
  On any pre-Marshmallow version all I need to do to turn the flash on/off was the following:</p>
  <pre><code>private void turnFlashOn(final Camera camera, int flashLightDurationMs) {
      if (!isFlashOn()) {
          final List&lt;String&gt; supportedFlashModes = camera.getParameters().getSupportedFlashModes();
          if (supportedFlashModes != null &amp;&amp; supportedFlashModes.contains(Camera.Parameters.FLASH_MODE_TORCH)) {
              mParams.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
              camera.setParameters(mParams);
          }
      }
  }
  </code></pre>
  <p>and</p>
  <pre><code>private void turnFlashOff(Camera camera) {
      if (camera != null) {
          final List&lt;String&gt; supportedFlashModes = camera.getParameters().getSupportedFlashModes();
          if (supportedFlashModes != null &amp;&amp; supportedFlashModes.contains(Camera.Parameters.FLASH_MODE_OFF)) {
              mParams.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
              camera.setParameters(mParams);
          }
      }
  }
  </code></pre>
  <p>Unfortunately, Marshmallow devices began to crash in the wild. Somehow <code>camera.getParameters()</code> and <code>camera.setParameters()</code> began to fail with messages such as:</p>
  <blockquote>
  <p>RuntimeException: getParameters failed (empty parameters)</p>
  <p>RuntimeException: setParameters failed</p>
  </blockquote>
  <p>I tried starting and stopping the preview before getting the parameters, which no longer throws errors. However the preview is not resumed when I call <code>camera.startPreview()</code>.</p>
  <p>I fear releasing the camera and reopening it is out of the question as this takes some seconds and would produce a bad experience.</p>
  <p>Any suggestions on how to turn the flashlight on/off in Marshmallow reliably?</p>