0

I'm designing an app (on version 2.2) that use the camera to capture photos.

I read from http://developer.android.com/sdk/android-2.3.html that version 2.3 and above have multiple cameras support. But i'm still a bit confused because when the camera is launched, it normally have a button that the user can click to switch between front-facing and rear cameras, right?

or

2.2 doesn't have this switch?

I want the user to be able to use both front and rear cameras. Is it possible on version 2.2 or should I use 2.3 and above?

Ronak Mehta
  • 5,971
  • 5
  • 42
  • 69
user1398267
  • 31
  • 1
  • 8

2 Answers2

1

Yes, 2.2 can only manage rear camera. For frontal camera you need to upgrade to 2.3+.

private int getBestCameraId() {

        PackageManager pm = m_mainThreadContext.getPackageManager();

        try {
            if (pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_FRONT)) {
                Log.i(TAG, "Phone has a frontal camera.");
                return Camera.CameraInfo.CAMERA_FACING_FRONT;
            } else {
                Log.i(TAG, "Phone has only rear camera.");
                return Camera.CameraInfo.CAMERA_FACING_BACK;
                }
        } catch (Exception e) {
                return Camera.CameraInfo.CAMERA_FACING_BACK;
    }

}

With this simple function it check whether the phone has a frontal or rear camera, and return the best. The id returned can be used in the Camera.open(id) to select the desired camera.

If in your Manifest you write:

<uses-sdk android:minSdkVersion="8" />

and you develop your project with libraries 2.3 (or +), the function i have posted works like a charm! I've used in a camera project, so trust me ;)

Davide Lorenzi
  • 348
  • 2
  • 6
0

Refer this this & this

For APIs >=9, you can use the Camera class to see if it has more than one camera, and query the CameraInfo

getNumberOfCameras

getCameraInfo:

And for Android 2.2 and lower versions, supports a single camera in its SDK.

Community
  • 1
  • 1
Shankar Agarwal
  • 34,573
  • 7
  • 66
  • 64