Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I select the right camera to turn on the flashlight, in Android 2.2?

my problem is that I'm trying to learn about the camera, and right now I have made an app that can turn on the Flashlight on my HTC Wildfire, my Wildfire runs Android 2.2.

Heres the code I'm using:

//Flash portion
camera = Camera.open();
parameters = camera.getParameters();
parameters.setFlashMode(Parameters.FLASH_MODE_TORCH);
camera.setParameters(parameters);

Now I let my friend test it, to see if it worked on his phone, but it didn't... He has an Optimus 2X(Android v. 2.2.2), and it has two cameras. When he opens the App nothing happens, and my suspicion tells me it is because it connects to the wrong camera. So I did my research and found that in 2.3 multiple Camera support was added!

But I have to run 2.2 version for it to work on my phone and his, and in 2.2 you CANNOT use:

Camera.open( cameraId );

But he told me that he has a flashlight application that has no problem turning on his flash. So why exactly can't I connect to it, and his flashlight app can?

like image 523
André Avatar asked Nov 13 '22 18:11

André


1 Answers

Please check these lines in your Manifest file :

<!-- Allows access to the flashlight -->
<permission android:name="android.permission.FLASHLIGHT"
         android:permissionGroup="android.permission-group.HARDWARE_CONTROLS"
         android:protectionLevel="normal"
         android:label="@string/permlab_flashlight"
         android:description="@string/permdesc_flashlight" />

Here are some projects related to flashlight, you can try the source code :

OpenSource Code : http://code.google.com/p/torch/source/browse/

Example showing how to enable the LED on a Motorola Droid : http://code.google.com/p/droidled/

Another Open Source Code : http://code.google.com/p/covedesigndev/

like image 112
Ravi Sharma Avatar answered Dec 17 '22 15:12

Ravi Sharma