Is there a way to get the users current Flash settings (for the camera) in Android?

走远了吗. 提交于 2019-12-11 20:25:25

问题


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


来源:https://stackoverflow.com/questions/20320748/is-there-a-way-to-get-the-users-current-flash-settings-for-the-camera-in-andro

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!