1

I got some example to set flash mode, cant make it work. I using it in a camera swap:

        final ImageButton button1 = (ImageButton) findViewById(R.id.bt_camera);
    button1.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            camera.release();
            idCam.id = idCamera(idCam.id);
            camera = Camera.open(idCam.id);
            Camera.Parameters parametro = camera.getParameters();
            parametro.setFlashMode(Parameters.FLASH_MODE_ON);
            camera.setParameters(parametro);
            camera.startPreview();
                try {
            camera.setPreviewDisplay(camHolder.id);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    });

Without the flash parameters, swap works fine.

Included in the manifest the permission:

<uses-feature android:name="android.hardware.camera" /> <uses-feature android:name="android.hardware.camera.autofocus" /> <uses-feature android:name="android.hardware.camera.flash" /> <uses-permission android:name="android.permission.CAMERA" />

But log returns:

05-21 09:25:02.985: D/IPCThreadState(24048): [DN #5] BR_CLEAR_DEATH_NOTIFICATION_DONE cookie 0x64fca0
05-21 09:25:03.260: D/AndroidRuntime(24048): Shutting down VM
05-21 09:25:03.260: W/dalvikvm(24048): threadid=1: thread exiting with uncaught exception (group=0x40ca4258)
05-21 09:25:03.283: E/AndroidRuntime(24048): FATAL EXCEPTION: main
05-21 09:25:03.283: E/AndroidRuntime(24048): java.lang.RuntimeException: setParameters failed
05-21 09:25:03.283: E/AndroidRuntime(24048):    at android.hardware.Camera.native_setParameters(Native Method)
05-21 09:25:03.283: E/AndroidRuntime(24048):    at android.hardware.Camera.setParameters(Camera.java:1714)
05-21 09:25:03.283: E/AndroidRuntime(24048):    at br.com.JairoFilho.teste4.Login$1.onClick(Login.java:66)
Bigflow
  • 3,616
  • 5
  • 29
  • 52
Jairo Filho
  • 342
  • 5
  • 17
  • Please take a look at this answer, it looks like almost the same problem: http://stackoverflow.com/questions/15652249/java-lang-runtimeexception-setparameters-failed-in-android4-1-1-version – Bigflow May 21 '13 at 12:57
  • Looks like not all devices allows any parameter. I added this: ` String xxx = parametro.getFlashMode(); Toast.makeText(getBaseContext(), xxx, Toast.LENGTH_LONG).show();` and it returns 'off'. Is there a way to find a device allowed parameter? – Jairo Filho May 21 '13 at 13:31
  • Only thing I can think of is to make an if statement for it: `String xxx = parametro.getFlashMode(); if (xxx.equals("off")){ //Do something }` – Bigflow May 21 '13 at 13:41
  • @JairoFilho The String value "off" returned when you call getFlashMode() is a valid flash mode state FLASH_MODE_OFF. If the device's camera does not support flash mode, then it will return null for getFlashMode() call. So, don't confuse "off" with null :) – VJ Vélan Solutions Aug 21 '13 at 02:37
  • @JairoFilho you can enum all flash modes supported by camera: list = camera.getParameters().getSupportedFlashModes(); if the list is null or empty then the camera doesn't have flash light or doesn't support chaning flash light mode. – user1991679 May 20 '14 at 09:05

0 Answers0