Is camera In Torch Mode - Android android.hardware

Android examples for android.hardware:Camera Feature

Description

Is camera In Torch Mode

Demo Code

import android.graphics.Bitmap;
import android.hardware.Camera;
import java.lang.reflect.Method;
import java.util.Collections;
import java.util.List;

public class Main{

    /** Returns true if the camera is in torch mode (flash always on) */
    public static boolean cameraInTorchMode(Camera camera) {
        return "torch".equals(getCurrentFlashMode(camera));
    }/*from  w w  w.j a va 2s.  c  om*/
    public static String getCurrentFlashMode(Camera camera) {
        Camera.Parameters params = camera.getParameters();
        try {
            Method getModeMethod = params.getClass().getMethod(
                    "getFlashMode");
            return (String) getModeMethod.invoke(camera);
        } catch (Exception ex) {
            return null;
        }
    }

}

Related Tutorials