Is there a way to get the users current Flash sett

2019-09-06 13:39发布

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?

3条回答
地球回转人心会变
2楼-- · 2019-09-06 14:05

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

查看更多
forever°为你锁心
3楼-- · 2019-09-06 14:14

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......
        }
    }
查看更多
何必那么认真
4楼-- · 2019-09-06 14:31
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;
}
查看更多
登录 后发表回答