I want to record a video with a flash light to be on to make focus on the capture.
Asked
Active
Viewed 1,969 times
-2
-
What you tried so far? – Nouman Ghaffar Mar 01 '16 at 09:53
-
Actually I'm not able to start camera and flash at same time. Not able to show the code. – PatidarNikunj Mar 01 '16 at 09:57
-
http://stackoverflow.com/questions/6068803/how-to-turn-on-camera-flash-light-programmatically-in-android – Nouman Ghaffar Mar 01 '16 at 09:59
-
http://www.mkyong.com/android/how-to-turn-onoff-camera-ledflashlight-in-android/ – Nouman Ghaffar Mar 01 '16 at 10:00
-
I know how to turn on Camera/Flash but can you please tell me how to turn on camera+flash light at same time??? – PatidarNikunj Mar 01 '16 at 10:02
-
Have you seen the links I share? – Nouman Ghaffar Mar 01 '16 at 10:02
-
Yes but there is either of flash or camera to be turn on want both at a time – PatidarNikunj Mar 01 '16 at 10:04
-
Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/104989/discussion-between-patidarnikunj-and-nouman-ghaffar). – PatidarNikunj Mar 01 '16 at 10:08
1 Answers
2
Add this to your manifest
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
Check if device has camera
boolean hasFlash = getApplicationContext().getPackageManager()
.hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);
Camera camera = Camera.open();
Parameters params = camera.getParameters();
to turn on the flash
params = camera.getParameters();
params.setFlashMode(Parameters.FLASH_MODE_TORCH);
camera.setParameters(params);
camera.startPreview();
to turn off the flash
params = camera.getParameters();
params.setFlashMode(Parameters.FLASH_MODE_OFF);
camera.setParameters(params);
camera.stopPreview();
in that case you can use SurfaceView add this to your xml
<SurfaceView
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="@+id/surface"
android:layout_weight="2"/>
then in activity
surfaceview=(SurfaceView)findViewById(R.id.surface);
surfaceholder=surfaceview.getHolder();
surfaceholder.addCallback(this);
surfaceholder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
@Override
public void surfaceCreated(SurfaceHolder surfaceHolder) {
try {
camera = Camera.open();
android.hardware.Camera.Parameters params = camera.getParameters();
params = camera.getParameters();
params.setFlashMode(android.hardware.Camera.Parameters.FLASH_MODE_TORCH);
camera.setParameters(params);
camera.setPreviewDisplay(surfaceholder);
camera.startPreview();
// Toast.makeText(getApplication(), "Create", Toast.LENGTH_LONG).show();
} catch (IOException e) { }
}

Nilesh Deokar
- 2,975
- 30
- 53
-
I already know this but I want to turn on camera as well as flash light at same time – PatidarNikunj Mar 01 '16 at 10:05