Note : Check this out (NEW): QR/Bar-code Scanner using “Zxing Fragment Library”
This guide is to explain how to add the functionality of scanning QR code/barcode to your project using android-zxinglib. The android-zxinglib is an android library project of zxing BarcodeScanner. This is a simplified version of BarcodesScanner project so as it does not contain the full functionality provided there.
1. Download android-zxinglib from Google Project downloads. (android-zxinglib-1.0.zip)
2. Create a new workspace and import the project ‘ZxingLib’.
You’ll see that this library project has less number of packages comparing to ‘BarcodeScanner’ project providing only the SCAN.
*Note: Project contains errors at switch statements of few classes. You can fix it by selecting the switch and (Press Ctrl +1), then it will suggest to convert switch to if-else statement.
2. Now create a new project to include the scanner. –> Goto project properties –> Android –> library project –> Add the ‘ZxingLib’ as library project.
Now you’ll see that it automatically add zxinglib.jar as dependencies and core.jar as private libraries to you Scanner project.
3. Add the following uses-permissions and activities to the AndroidManifest.xml of Scanner project
<uses-permission android:name="android.permission.CAMERA" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-feature android:name="android.hardware.camera" /> <uses-feature android:name="android.hardware.camera.autofocus" /> <uses-permission android:name="android.permission.VIBRATE" />
<activity android:name="jim.h.common.android.lib.zxing.CaptureActivity" android:screenOrientation="landscape" android:configChanges="orientation|keyboardHidden" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:windowSoftInputMode="stateAlwaysHidden" />
4. Add the following line to ScannerActivity at onCreate().
startActivity(new Intent(this, CaptureActivity.class));</pre> <pre>
*Note: Comment the line //activity.finish() at handleMessage() of CaptureActivityHandler.class of ZxingLib project
Deploying…
Run the application.. when it start the CaptureAcitvity.class, it will open your device camera and starts the scanning. When you place a barcode at the target view, application will capture the barcode and you’ll see the output as follows.
Thank You 🙂
Hi, i follow your article and try it on my testing application. it’s work but i cannot see the result from scanned bar. it just like the app hang on the captured picture. can you help me for the result for scanned bar code ?
LikeLike
Hi,
Try overriding the handleDecode() method on CaptureActivity.class. In order to extend CaptureActivity class you will need to remove the “final” modifier of CaptureActivity.class in the library project
public class ScanResultActivity extends CaptureActivity {
@Override
public void handleDecode(Result rawResult, Bitmap barcode) {
super.handleDecode(rawResult, barcode);
String resultContent = rawResult.toString();
String resultFormat = rawResult.getBarcodeFormat().toString();
}
}
LikeLike