5

I know that we can access the front-facing camera on pre-Gingerbread Galaxy S devices by setting the "camera-id" Camera parameter:

Camera cam = Camera.open();
Camera.Parameters params = cam.getParameters();
params.set("camera-id", 2);

The problem is, not all Galaxy devices have a front-facing camera. These devices DO have "camera-id" parameter, AND it allows me to set it to 2 (front). As far as I have found, the only way to determine presence/absence of FFC is to see if startPreview() throws an exception when "camera-id" is 2. This is kind of an awkward fix especially when I'm trying to support multiple devices.

Has anyone found a way to query the number of cameras on a 2.1 or 2.2 Galaxy S, or at least determine the presence of a front-facing camera?

Thanks!

1 Answer 1

2

If you require a front-facing camera you can put that in your AndroidManifest.xml like this:

<uses-feature android:name="android.hardware.camera.front" android:required="true" />

If you don't require it and want to check at runtime you can use the PackageManager like this:

PackageManager.hasSystemFeature(PackageManager. FEATURE_CAMERA_FRONT);
2
  • Thanks for your reply, but that feature is only available on Gingerbread (2.3) and I need this to work on 2.1/2.2 devices, using the not-really-documented Samsung camera-switch API.
    – mrb
    May 18, 2011 at 17:57
  • The AndroidManifest part will still work. Other than that there is really no way to do it. The Android core didn't support front facing cameras until 2.3 so the only way to do it in earlier versions would be to use device-specific extensions.
    – CaseyB
    May 18, 2011 at 18:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.