How to integrate ZXing api with front camera in android?

Ayush Verma picture Ayush Verma · Dec 27, 2011 · Viewed 7.4k times · Source

I just wanted to integrate ZXing API in my android app, but cant find the proper documentation.

Answer

Tiago picture Tiago · Dec 13, 2012

Follow these steps:

1) Download the source code here: http://code.google.com/p/zxing/source/checkout

2) Import the source code as a new project into Eclipse and make the root of the project be the folder /android (found in the source code).

3) Make sure to also copy everything under /core/src to this project, as the source code imported on step 2 requires it.

4) Make sure to set your compiler to Java 1.6 on Eclipse (right click on your project, properties, Java Compiler) otherwise you will get some errors regarding the @Override annotation.

5) Edit the class com.google.zxing.client.android.camera.open.GingerbreadOpenCameraInterface as follows:

  while (index < numCameras) {
       Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
       Camera.getCameraInfo(index, cameraInfo);


       if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
           break;
       }
       /*//Original code (gets the back camera. This is NOT what you want!)
       if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
    break;
  }*/
  index++;
}

5) Make this project as a library, as easily described here: http://developer.android.com/tools/projects/projects-eclipse.html#SettingUpLibraryProject

6) Reference this project into your real project (right click on your real project, properties, Java Build Path, Projects, Add).

7) You're done! =)

Hope it helps.