I am trying to write a small Android widget with a button that turns on / off the camera flashlight. I know there are thousands of it there, but I want to learn Android (and small steps seem to be the best way).
Now I have read the official documentation, some free tutorials on the Internet, and searched here on stackoverflow. As long as I don't get any errors, LogCat says that everything works as desired. But when I test the application on my Galaxy Nexus, the switch turns on / off, as it should, but the Cams LED does not turn on / off.
Here is my code (only those parts where the LED is really on / off):
if (isLightOn) { Log.d("receiver", "flashlight is on, disabling it"); if (camera != null) { param.setFlashMode(Camera.Parameters.FLASH_MODE_OFF); camera.setParameters(param); camera.release(); camera = null; isLightOn = false; } } else { Log.d("receiver", "flashlight is off, enabling it"); camera = Camera.open(); if(camera == null) { Toast.makeText(context, R.string.no_camera, Toast.LENGTH_SHORT).show(); } else { // Set the torch flash mode param.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH); try { camera.setParameters(param); isLightOn = true; } catch (Exception e) { Toast.makeText(context, R.string.no_flash, Toast.LENGTH_SHORT).show(); } } }
Any ideas why this is not working as intended?
source share