Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to integrate ZXing api with front camera in android? [closed]

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

like image 947
Ayush Verma Avatar asked Dec 27 '11 07:12

Ayush Verma


2 Answers

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.

like image 53
Bitcoin Cash - ADA enthusiast Avatar answered Oct 24 '22 07:10

Bitcoin Cash - ADA enthusiast


The latest version of Barcode Scanner as well as the ZXing source code now supports front facing camera.

like image 31
Adam Nybäck Avatar answered Oct 24 '22 07:10

Adam Nybäck