Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>UPDATE</strong></p> <p>I think the key is you are running Android 4.1.2. Since Android 4.0, if you want to use the Camera Device, even if you only want to use the flash, you are forced to use a SurfaceView.</p> <p>In the previous answer (below), I gave you a link to a <a href="https://code.google.com/p/torch/source/browse/branches/ics/src/com/colinmcdonough/android/torchics/Torch.java" rel="nofollow noreferrer">Torch app which uses SurfaceView</a>. Try it or adapt it to your code.</p> <p><strong>PREVIOUS ANSWER:</strong></p> <p>As stated in many other cases (<a href="https://stackoverflow.com/a/5017623/1587345">like this one</a>), you may be facing a Device-Specific issue that is quite common in the Android world. </p> <p>Although <code>getSupportedFlashModes()</code> may return <code>FLASH_MODE_TORCH</code> on nearly every device, many of them don't actually support it.</p> <p>Anyway, you could try these:</p> <ul> <li>Use <code>camera.startPreview();</code> after <code>camera = Camera.open();</code></li> <li>Try setting <code>FLASH_MODE_OFF</code> initially (before <code>camera.startPreview();</code>). </li> <li>Check if <a href="https://code.google.com/p/torch/" rel="nofollow noreferrer">this Torch app</a> works in your device. In case it does, you have the source code to compare it to yours.</li> <li>Download a Torch app from the Play Store to test if it's a device issue or not.</li> <li>Post the issue in a <a href="http://www.droidforums.net/forum/droid-bionic-tech-support/" rel="nofollow noreferrer">Droid Bionic support forum</a>.</li> </ul> <p>UPDATE: I would say the <code>final</code> keyword is a problem in your code. Try changing it to:</p> <pre><code>//camera = Camera.open(); //final Parameters p = camera.getParameters(); button.setOnClickListener(new OnClickListener() { public void onClick(View arg0) { if (isFlashOn) { Log.i("info", "torch is turned off!"); cam.stopPreview(); cam.release(); isFlashOn = false; button.setText("Tap to turn flashlight on."); } else { Log.i("info", "torch is turned on!"); camera = Camera.open(); Parameters p = camera.getParameters(); p.setFlashMode(Parameters.FLASH_MODE_OFF); camera.setParameters(p); camera.startPreview(); p.setFlashMode(Parameters.FLASH_MODE_TORCH); camera.setParameters(p); isFlashOn = true; button.setText("Tap to turn flashlight off."); } } }); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload