Question

I need to ask a questrion related to barcode scanning, I am using an app that scans barcodes and searches the web fr the results. Now this is my method where i create instance of my camera object

   /** A safe way to get an instance of the Camera object. */
public static Camera getCameraInstance() {
    Camera c = null;
    try {
        c = Camera.open();
    } catch (Exception e) {
    }
    return c;
}

For scanning i am using a Zbar library. My question is regarding the device Asus Nexus 7. I dont have that device with me currently, but i know that it just has the front camera and no Back camera in it. How to make it work in case of devices with just the front camera and no back camera? Will it work fine with my code ? if i add the the following uses-feature android:name = "android.hardware.camera.front" android:required="false"

My sole purpose is to allow the user to scan the barcode, if there are both the front and back camrera it should scan via Back camera and if it has only the front camera it should scan via that camera only, How am i to proceed in it? All suggestions will be welcomed. :-D

Was it helpful?

Solution

Before Android 2.3, there was no API for accessing a front camera, and all device cameras were rear cameras. The API call you are using is the original one, and will still only open a rear-facing camera, for compatibility. On the Nexus 7 you will get null.

You need Camera.open(int) to choose another camera. On the Nexus 7 since there is just one camera, it will definitely be opened with Camera.open(0). But really you need to interrogate all available cameras and pick the one you want.

The source code from zxing / Barcode Scanner shows how it opens a rear camera, unless none is available, in which case a front camera is opened.

(Note that Barcode Scanner+ will let you choose between them too, if you have it.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top