Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exception java.lang.RuntimeException: setParameters failed

I am getting following error

Exception java.lang.RuntimeException: setParameters failed
android.hardware.Camera.native_setParameters (Camera.java)
android.hardware.Camera.setParameters (Camera.java:1946)

in code below. I have no clue what wrong i am doing below.

        Camera mCamera = Camera.open();
        Parameters params = mCamera.getParameters();

        if (params.getFlashMode() != null)
            params.setFlashMode(Parameters.FLASH_MODE_OFF);

        if (nightMode && params.getSceneMode() != null)
            params.setSceneMode(Parameters.SCENE_MODE_NIGHT);

        if (params.getSupportedFocusModes().contains(Parameters.FOCUS_MODE_CONTINUOUS_VIDEO)) {
            params.setFocusMode(Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);
        } else if (params.getSupportedFocusModes().contains(Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) {
            params.setFocusMode(Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
        } else if (params.getSupportedFocusModes().contains(Camera.Parameters.FOCUS_MODE_INFINITY)) {
            params.setFocusMode(Parameters.FOCUS_MODE_INFINITY);
        }

        mCamera.setParameters(params);

this error is occurring in some devices like samsung mostly. Requesting for help.Thanks in advance.

like image 750
SimpleCoder Avatar asked Mar 11 '23 23:03

SimpleCoder


1 Answers

Your params could be not supported by device. You can detect available focus modes with getSupportedFocusModes method of Camera.Parameters class. If some mode doesn't contain in this list, you can't set it to your camera.

Edit

As Alex said in comment you can see error message in logcat.

like image 53
Ircover Avatar answered Mar 21 '23 08:03

Ircover