18

I am turning ON Camera LED light using FLASH_MODE_ON.

Samsung Galaxy Ace have only three flash modes : on, off and auto.

FLASH_MODE_TORCH not working in Samsung Galaxy Tab & Samsung Galaxy Ace 2.2.1

Here is my code how i am turning ON my Camera LED

    Camera cam;
    cam = Camera.open();     
    Parameters params = cam.getParameters();
    params.setFlashMode(Parameters.FLASH_MODE_ON);
    cam.setParameters(params);
    cam.startPreview();
    cam.autoFocus(new AutoFocusCallback() {
                public void onAutoFocus(boolean success, Camera camera) {
                }
     });

And turning it off by using :

cam.stopPreview();
cam.release();

Code Reference : Use camera flashlight in Android

But the problem is LED Light remains on just for 5sec. It just then turns OFF automatically.

Can anyone please tell where can be the problem. OR any way to turn ON the LED light continuously till its requested to Stop.

Community
  • 1
  • 1
Kartik Domadiya
  • 29,868
  • 19
  • 93
  • 104

1 Answers1

10

I will soon released a new version of my app to support to galaxy ace.

You can download here: https://play.google.com/store/apps/details?id=droid.pr.coolflashlightfree

In order to solve your problem you should do this:

this._camera = Camera.open();     
this._camera.startPreview();
this._camera.autoFocus(new AutoFocusCallback() {
public void onAutoFocus(boolean success, Camera camera) {
}
});

Parameters params = this._camera.getParameters();
params.setFlashMode(Parameters.FLASH_MODE_ON);
this._camera.setParameters(params);

params = this._camera.getParameters();
params.setFlashMode(Parameters.FLASH_MODE_OFF);
this._camera.setParameters(params);

don't worry about FLASH_MODE_OFF because this will keep the light on, strange but it's true

to turn off the led just release the camera

Ivan
  • 4,186
  • 5
  • 39
  • 72
Pedro Rainho
  • 4,234
  • 1
  • 19
  • 21
  • can you please provide the logcat ? – Kartik Domadiya Mar 21 '12 at 13:30
  • no :( I didn't tried it on my phone, but on the phone of a friend of mine :( If i will have the chance i will surely post the logcat. – Ivan Mar 21 '12 at 13:59
  • I've tested on a galaxy ace and it worked. In my app there is a debug screen. If you press volume key down you will enter in that debug screen. If you check use auto focus, then press initialize, the press on then press off imididatly after on you will see that the led stays on. To turn off the led just press release. – Pedro Rainho Mar 21 '12 at 22:43
  • The exception was my fault, i solved it. I tried on the Galaxy of of my colleague, but the flashlight didn't turn on. This is my code, maybe i forgot something? http://pastebin.com/VFg1eVKF – Ivan Mar 22 '12 at 12:37
  • I see your problem. Add a small delay between FLASH_MODE_ON and FLASH_MODE_OFF. Setting both at the same time, can causes the led to stay off. – Pedro Rainho Mar 24 '12 at 22:38
  • @Pedro Rainho :- do you have any idea how can i change the Flashlight intensity on non rooted devices? – NIKHIL Mar 11 '13 at 10:43
  • I am facing the same issues... Flash light stays for a while and it offs automatically. Have anyone found any solution for this, please post it here. – Hitesh Kamani Apr 16 '16 at 10:49