-1

I am trying to determine if flash is on or off so that with one button I can toggle it on and off. Here is my code :

Camera cam = getCameraInstance(); //A method that opens the cam
            Camera.Parameters parameters = cam.getParameters();
            System.out.println("Current flash mode " + parameters.getFlashMode());
            System.out.println("flash mode off equals to : " + Camera.Parameters.FLASH_MODE_OFF);
            System.out.println(parameters.getFlashMode() == Camera.Parameters.FLASH_MODE_OFF);

The output for the first two syso's is off. Naturally I assumed that because they both return an off string putting the == operator between them would return true (thus allowing me to check if flash is on) but it returns false. Any idea why?

I am targeting for api 16 and testing on a Marshmallow device

Sergey Emeliyanov
  • 5,158
  • 6
  • 29
  • 52
Bar Akiva
  • 1,089
  • 1
  • 11
  • 23

1 Answers1

5

If you check docs you'll see that these parameters are Strings, and you don't compare strings in Java with ==. You do that with equals.

Stefan Golubović
  • 1,225
  • 1
  • 16
  • 21