title: How to turn ON and OFF Device flash light?
body: <p>I want to turn on only camera <code>flash light</code> (not with camera preview) programmatically in Android. I googled for it but the help I found was not working on my Samsung Galaxy ACE.</p>
  
  <p>By using this code able to turn on for few seconds after that it goes to off automatically with out doing anything on the UI. If I try to turn on again getting force close.</p>
  
  <pre><code>private void turnOn() {
  
      clicked = true;      
      mCamera = Camera.open();
      Parameters params = mCamera.getParameters();
      params.setFlashMode(Parameters.FLASH_MODE_ON); 
      mCamera.setParameters(params);
      mCamera.startPreview();
      mCamera.autoFocus(new AutoFocusCallback() {
          public void onAutoFocus(boolean success, Camera camera) {
          }
      });
  }
  </code></pre>
  
  <p>For turn OFF </p>
  
  <pre><code>private void turnOff() { 
      clicked = false;         
      if (mCamera != null) {
          mCamera.stopPreview();
          mCamera.release();
      }
  }
  </code></pre>
  
  <p>Declared these manifest permissions </p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.CAMERA" /&gt;
  &lt;uses-permission android:name="android.permission.FLASHLIGHT" /&gt;
  
  &lt;uses-feature android:name="android.hardware.camera" /&gt;
  &lt;uses-feature android:name="android.hardware.camera.autofocus" /&gt;
  &lt;uses-feature android:name="android.hardware.camera.flash" /&gt;
  </code></pre>
  
  <p>Can any body tell me How to turn on the flash light for a long time upto the use click on OFF button. Is it requires any third party libraries. I saw this app in the Google play <a href="https://play.google.com/store/apps/details?id=com.devuni.flashlight&amp;feature=search_result#?t=W251bGwsMSwxLDEsImNvbS5kZXZ1bmkuZmxhc2hsaWdodCJd" rel="nofollow">Tiny flash</a> how they did this app..</p>
  
  <p>From my after turn on it goes to off in <code>2 sec</code> I did not get what's the problem in this.</p>