I want turn on the Android flash for 50 miliseconds, but I cannot seem to get it to work. The debugger will run through the code with no errors, but the camera will not turn on. I have tried stopping on the await command to see if the time was too short, but I still cannot get the camera to turn on. I am confused because I have see similar code in multiple tutorials. The only difference is that mine is not running on the main activity.
Manifest:
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.FLASHLIGHT" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.flash" />
<!-- Unrelated code -->
<activity android:name="SyncActivity"
android:label="@string/app_name" >
</activity>
Code:
if(getApplicationContext().getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH)) {
CountDownLatch latch = new CountDownLatch(1);
Camera androidCamera = Camera.open();
Camera.Parameters p = androidCamera.getParameters();
p.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
androidCamera.setParameters(p);
//Flash and then turn off
androidCamera.startPreview();
latch.await(50, TimeUnit.MILLISECONDS);
androidCamera.stopPreview();
androidCamera.release();
} else {
throw new Exception("Cannot access Android Flash");
}