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