Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Samsung Galaxy S: How to determine presence of front-facing camera?

Tags:

android

camera

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!

like image 615
mrb Avatar asked Nov 04 '22 21:11

mrb


1 Answers

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);
like image 59
CaseyB Avatar answered Nov 15 '22 12:11

CaseyB