[android] Turn ON/OFF Camera LED/flash light in Samsung Galaxy Ace 2.2.1 & Galaxy Tab

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.

This question is related to android android-camera galaxy samsung-mobile flashlight

The answer is


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


Examples related to android

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How to implement a simple scenario the OO way My eclipse won't open, i download the bundle pack it keeps saying error log getting " (1) no such column: _id10 " error java doesn't run if structure inside of onclick listener Cannot retrieve string(s) from preferences (settings) strange error in my Animation Drawable how to put image in a bundle and pass it to another activity FragmentActivity to Fragment A failure occurred while executing com.android.build.gradle.internal.tasks

Examples related to android-camera

Android camera android.hardware.Camera deprecated How to get file name from file path in android Android Camera Preview Stretched How to compress image size? Android open camera from button How to capture and save an image using custom camera in Android? Android Camera : data intent returns null How to measure height, width and distance of object using camera? Turn ON/OFF Camera LED/flash light in Samsung Galaxy Ace 2.2.1 & Galaxy Tab How to turn on front flash light programmatically in Android?

Examples related to galaxy

Unable to capture screenshot. Prevented by security policy. Galaxy S6. Android 6.0 Hide "NFC Tag type not supported" error on Samsung Galaxy devices Turn ON/OFF Camera LED/flash light in Samsung Galaxy Ace 2.2.1 & Galaxy Tab

Examples related to samsung-mobile

Hide "NFC Tag type not supported" error on Samsung Galaxy devices Chrome's remote debugging (USB debugging) not working for Samsung Galaxy S3 running android 4.3 sendUserActionEvent() is null Turn ON/OFF Camera LED/flash light in Samsung Galaxy Ace 2.2.1 & Galaxy Tab

Examples related to flashlight

Turn ON/OFF Camera LED/flash light in Samsung Galaxy Ace 2.2.1 & Galaxy Tab