5

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.

2 Answers 2

6

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Same is true for other parameters. On some devices things can go really weird, like choosing a scene mode may contradict a focus mode, etc. The only way to steer safely on devices that you did not verify specifically, is to always catch RuntimeException on setParameters(), and also call getParameters() immediately after that, because setParameters() may also fail silently. Sometimes, logcat (for system camera service) can give you a hint of what went wrong.
You are right, i am checking this solution on live devices. I ll surely mark this as accepted after verification.
1

you must check if the focus mode supported by the user device, not all devices has camera focus mode, you do it like this:

    public boolean support_focus(Camera camera){
     Camera.Parameters parameters = camera.getParameters();
     List<String> focusModes = parameters.getSupportedFocusModes();
     if (focusModes.contains(Camera.Parameters.FOCUS_MODE_AUTO))
         return true;
     else
         return false;
    }

this check if device support FOCUS_MODE_AUTO, change that with your desired Parameter.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.