Search code examples
javaandroidandroid-cameraandroid-camera2

In Android how to check if device has front flash (Camera2 API)


I have developed app that can toggle rear and front flashes. But if a device hasn't got front flash the app crashes. Can I check device front flash availability? Like if front flash unavailable show toast and disable the button.

Any help would be appreciated.


Solution

  • Something like this I guess:

    boolean flashAvailable = cameraCharacteristics.get(cameraCharacteristics.FLASH_INFO_AVAILABLE);
    

    public static final Key FLASH_INFO_AVAILABLE

    Will be false if no flash is available.

    If there is no flash unit, none of the flash controls do anything. This key is available on all devices.