Turn Camera LED Flash On

How to Turn Camera LED Flash On

* Note: This code may or may not work on some devices.
Works on Samsung Galaxy Player, Android 2.3.6, (Level 10)

1. Create an Android project, if you don't already have one.

2. Open AndroidManifest.xml and add the below line.

</manifest>
<uses-permission android:name="android.permission.CAMERA" />
    <application

3. Open MainActivity.java file and add the below to the imports section. 

import android.hardware.Camera;import  android.hardware.Camera.Parameters;

4. Add the below code between the public class and the onCreate method

public class MainActivity extends Activity{

private Camera camera;
 Parameters p;

    @Override
    public void onCreate(Bundle savedInstanceState)    {

5. Add the below code in the onCreate method

myCamera = Camera.open(); //needs import android.hardware.Camera;
p = myCamera.getParameters(); //needs import  android.hardware.Camera.Parameters;
p.setFlashMode(Parameters.FLASH_MODE_TORCH);
myCamera.setParameters(p);
myCamera.startPreview();

6. Compile and run!

Resources: