saiket saiket - 3 months ago 77
Android Question

How to turn on camera flash light programmatically in Android?

I want to turn on only the camera flash light (not with camera preview) programmatically in Android. I googled for it but the help i found referred me to this page

Does anyone have any links or sample code?


For this you should do like :

  1. Check whether flash light is available or not ?

  2. If yes then Turn Off/On

  3. If no then you can do whatever according to your app. needs

For Checking availability of flash in device:

You can use the following


which will return true if a flash is available, false if not.

See for more information.

For turning on/off flashlight :

I googled out and got this about android.permission.FLASHLIGHT. Android manifests' permission looks promising:

 <!-- Allows access to the flashlight -->
 <permission android:name="android.permission.FLASHLIGHT"
             android:description="@string/permdesc_flashlight" />

Then make use of Camera and set Camera.Parameters. The main parameter used here is FLASH_MODE_TORCH.


Code Snippet to turn on camera flash light.

Camera cam =;     
Parameters p = cam.getParameters();

Code snippet to turn off camera led light.


I just found a project that uses this permission. Check quick-settings' src code. here (Note: This link is now broken)

For Flashlight directly look (Note: This link is now broken)

Update6 You could also try to add a SurfaceView as described in this answer LED flashlight on Galaxy Nexus controllable by what API? This seems to be solution that works on many phones.

Update 5 Major Update

I have found alternate Link(for above broken links): You can now use this link. [Update : 14/9/2012 This link is now broken]

Update 1

Another OpenSource Code :

Update 2

Example showing how to enable the LED on a Motorola Droid :

Another Open Source Code :

Update 3 (Widget for turning on/off camera led)

If you want to develop a widget that turns on/off your camera led, then you must refer my answer Widget for turning on/off camera flashlight in android..

Update 4

If you want to set intensity of light emerging from camera LED you can refer Can I change the LED intensity of an Android device? full post.. Note that only rooted HTC devices support this feature.

Issues :

There are also some problems while turning On/Off flashlight. eg. for the devices not having FLASH_MODE_TORCH or even if it has, then flashlight doesnot turn ON etc.

Typically Samsung creates alot of problems.

You can refer about problems in the given below list:

Use camera flashlight in Android

Turn ON/OFF Camera LED/flash light in Samsung Galaxy Ace 2.2.1 & Galaxy Tab