Android test if front camera supports flash

前端 未结 2 1602
感动是毒
感动是毒 2020-12-06 08:29

I know is possible to detect if camera has flash integrated, using a method like this:

 /** 
 * @return true if a flash is available, false if not
 */
public         


        
2条回答
  •  一个人的身影
    2020-12-06 08:48

    I figured this by myself and I post here the solution, which is actually very simple:

    /**
     * Check if Hardware Device Camera can use Flash
     * @return true if can use flash, false otherwise
     */
    public static boolean hasCameraFlash(Camera camera) {
        Camera.Parameters p = camera.getParameters();
        return p.getFlashMode() == null ? false : true;
    }
    

    The above method is different by this one:

    /**
     * Checking availability of flash in device.
     * Obs.: If device has 2 cameras, this method doesn't ensure both cameras can use flash. 
     * @return true if a flash is available in device, false if not
     */
    public static boolean isFlashAvailable(Context context) {
        return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);
    }
    

提交回复
热议问题