Samsung Galaxy S5 Camera Torch not working

十年热恋 提交于 2019-12-01 12:55:45

I'm doing it slightly different.. maybe it will help you!

                params = getCamera().getParameters();
    ...

                //Check if device supports torch mode, If YES then enable
                List<String> supportedFlashModes = params.getSupportedFlashModes();
                if (supportedFlashModes != null && supportedFlashModes.contains(Parameters.FLASH_MODE_TORCH)){
                    params.setFlashMode(Parameters.FLASH_MODE_TORCH);
                    torchModeOn  = true;
                }
...

                getCamera().setParameters(params);

In comparison I'm using Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE and NOT using setFocusAreas, setMeteringArea, setAutoWhiteBalanceLock, setWhiteBalance or setAutoExposureLock.

After seeing your code, i tried to incorporate each one individually to see if it would better affect my pictures, with no luck. (My app requires close-up pictures as well.

Parameters.FOCUS_MODE_MACRO was not working well for me at all on any of the devices i tried it with..

EDIT:

Here is the order i am setting up my camera incase it helps...

        setCameraDisplayRotation();

        params = getCamera().getParameters();

        setFocusMode();

        //Check if device supports torch mode, If you YES then set on
        List<String> supportedFlashModes = params.getSupportedFlashModes();
        if (supportedFlashModes != null && supportedFlashModes.contains(Parameters.FLASH_MODE_TORCH)){
            params.setFlashMode(Parameters.FLASH_MODE_TORCH);
            torchModeOn  = true;
        }

        setImageResolution();

        getCamera().setParameters(params); // update params before preview.setCamera
        preview.setCamera(getCamera());   

        //... some custom code for determining the current screens available space for the preview

        params.setPreviewSize(size.width, size.height);

        if(setHiddenParameter(params, "zsl-values", "zsl", "on")){
            setUsingZsl(true);
        };

        getCamera().setParameters(params); //update params after preview init

You have to use new camera2 API in Android Lollipop

Sample Code github

and developer site

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