I just wanted to integrate ZXing API in my android app, but cant find the proper documentation.
问题:
回答1:
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.
回答2:
The latest version of Barcode Scanner as well as the ZXing source code now supports front facing camera.
回答3:
UPDATE:
As the ZXing's FAQ has been updated since I posted this answer, the content below is no longer accurate:
Have you read ZXing's FAQ?
Can this be used on Android devices with only a front-facing camera, like the Nexus 7 tablet? Not at this time. The application requires a camera. In Android, only rear cameras are considered 'real' cameras, and so devices with only a front camera are incompatible. Further, API support for front cameras appeared in a later Android release than is currently required by the app. Front-facing cameras tend to have a less sensitive CCD and lack auto-focus, making them difficult to scan with anyway.
However, Barcode Scanner+ does support devices with only a front camera.
Besides, although I think this is not totally impossible if you can connect the front camera. Therefore, I think you should take a look at the Camera Section of Android Documentation: here and here