1

I am trying to make a small android app were I want to turn on the flash light on my LG P970 without actually turning on the camera application. Is this possible because from what information I have gathered so far you need to run the camera app to turn on the light.

rptwsthi
  • 10,094
  • 10
  • 68
  • 109
Nangu Haci
  • 153
  • 3
  • 5
  • 12

1 Answers1

0

There are several Open-Source flashlight apps for Android out there. If you look at their source you can see how they use it

Camera mCamera;
/* [...] */
public void initCamera() {
    /* see their source for more */
}

public void lightOff() {
    if (hasSurface && hasCamera) {
            mParameters.setFlashMode(Parameters.FLASH_MODE_OFF);
            mCamera.setParameters(mParameters);
    }
}

public void lightOn() {
    if (this.isShown() && hasCamera) {
            if (mParameters == null) {
                    setParameters();
            }
            mParameters.setFlashMode(Parameters.FLASH_MODE_TORCH);
            mCamera.setParameters(mParameters);
    } else {
            initCamera();
    }
}
Community
  • 1
  • 1
lambda
  • 3,295
  • 1
  • 26
  • 32