Is there a possibilty to activate front camera flash on Samsung phones?

时间:2019-04-08 13:02:12

标签: java android android-camera android-camera2 flashlight

Im currently trying to activate the built in front flashlight on a Samsung Galaxy A6, but the device provides information like there is no built in front flash.

I've already tried different methods, which can be found by searching for activating flash.

  1. First Try was to get supportedFlashModes and then activate the flash by using setParameters (API < 23). But simply the getParameters() for the front camera doesn't return any information of the built in front flash. For the app it just seems like there is no front flash available.

  2. Then i tried to use the Camera2 API, introduced in API >= 23 and there the same Problem occurs. Fetching camera characteristics and then check if FLASH_INFO is available just results in returning false. Also trying to just activate the flash unit with setTorchMode(FRONT_CAMERA, true) throws an exception which says: No flash unit available.

I currently only have Samsung Galaxy A6 as test device with built in front flash. The same code works fine for the rear (back) camera without any problems.

ad 1)

try {
            Camera camera;
            camera = Camera.open(cameraId);

            if (camera == null) {
                return false;
            }

            Camera.Parameters parameters = camera.getParameters();

            if (parameters.getFlashMode() == null) {
                camera.release();
                return false;
            }
    ...

It just quits at that point because .getFlashMode() returns null for the front camera. Next steps would be to check the supportedFlashModes and then call setParamater of Camera.

ad 2)

try {
        String camID = null;
        for(String cameraID : mCameraManager.getCameraIdList()) {
            CameraCharacteristics cameraCharacteristics = mCameraManager.getCameraCharacteristics(cameraID);

        int orientation = cameraCharacteristics.get(CameraCharacteristics.LENS_FACING);
        if (orientation == CameraCharacteristics.LENS_FACING_FRONT) {

                if(cameraCharacteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE)) {
                        camID = cameraID;
                    }
        }

        if(camID != null) {
            mCameraManager.setTorchMode(camID, true);
        }

    } catch (Exception exc) {
        ...
    }

These are only snippets for simply activating the front flash, but both methods act like the hardware response without a built in front flash.

1 个答案:

答案 0 :(得分:0)

经过研究,似乎一些电话制造商正在使用专用API来控制硬件。特别是三星和华为正在利用这一点。设备上的主相机应用主要由该API控制,因此可以按预期使用Frontflash。但是,即使像Instagram和Snapchat这样的大型相机应用也无法摆脱这种情况,并且也无法激活例如Frontflash。

出于个人目的,硬件只是不提供某些功能来激活某些设备上的Frontflash,而只是做出反应,就像没有内置的frontflash。 目前没有针对此问题的解决方案。

现有的解决方法是将屏幕变白,以减轻手机正面的环境。