0

Can we get the flash settings from the native camera app programmatically?

I mean to say, for example, if the user meddles with the flash modes in the default camera app, I want to read the flash mode set by him on my app, which is to run in the background. Is this possible?

SoulRayder
  • 5,072
  • 6
  • 47
  • 93

3 Answers3

1

In order to get the current flash mode, as Mr. Harshit suggested you need to getFlashMode(). For getting the same you may use the below code

Parameters params;
Camera cam;
cam=Camera.open();
params=cam.getParameters();
System.out.println(params.getFlashMode()); 

Try this and see if this works...

Niko
  • 1,367
  • 1
  • 13
  • 37
  • Hi Niko, I have tried this method. But since I am trying to check from my app which flash mode is selected from the native camera app, there is an exception because the camera object declared in my app tried to access the camera, which already has been accessed from the native camera app. So this approach doesn't work for my requirements. Any other way to do this? – SoulRayder Dec 02 '13 at 05:46
0
private boolean hasFlash(){
    Parameters params = mCamera.getParameters();
    List<String> flashModes = params.getSupportedFlashModes();
    if(flashModes == null) {
        return false;
    }

    for(String flashMode : flashModes) {
        if(Parameters.FLASH_MODE_ON.equals(flashMode)) {
            return true;
        }
    }

    return false;
}
Harshit Rathi
  • 1,862
  • 2
  • 18
  • 25
  • This would work if I created a custom camera app of my own. However, I am monitoring an existing camera app , to see whether user is changing camera settings in the existing camera app. For me to use getflashmode(), don't I have to create a camera object and open it first? From what I have tried till now, it generates an exception because the existing camera app also needs to access the same camera which my camera object accesses. – SoulRayder Dec 02 '13 at 05:29
  • I dont need to open a camera object for this? – SoulRayder Dec 02 '13 at 06:01
0

First check whether flashLight is supported or not

context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);

which will return true if a flash is available, false if not.

Check if flash is AUTO, ON, or OFF as:

 List<String> flashModes = cameraParams.getSupportedFlashModes();

    if(flashModes!=null && flashModes.size()>0)
    {
        if(cameraParams.getFlashMode().equals(android.hardware.Camera.Parameters.FLASH_MODE_ON))
        {
         //DO STUFF...
        }
        else if(cameraParams.getFlashMode().equals(android.hardware.Camera.Parameters.FLASH_MODE_OFF))
        {
        //DO STUFF......
        }
        else if(cameraParams.getFlashMode().equals(android.hardware.Camera.Parameters.FLASH_MODE_TORCH))
        {
        //DO STUFF......
        }
        else if(cameraParams.getFlashMode().equals(android.hardware.Camera.Parameters.FLASH_MODE_AUTO))
        {
        //DO STUFF......
        }
    }
Zar E Ahmer
  • 33,936
  • 20
  • 234
  • 300