-->

Is there a way to get the users current Flash sett

2019-09-06 13:42发布

问题:

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?

回答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...



回答2:

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;
}


回答3:

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......
        }
    }