I used zxing-android-embedded . It handles zxing-core for you, automatically opens the camera in a separate stream, and even has documents / examples for user use. In addition, the authors record often (every ~ 2 weeks) and quickly respond to problems. It scans QR and barcodes out of the box.
Add permissions for the camera in AndroidManifest.xml:
<uses-feature android:name="android.hardware.camera" /> <uses-feature android:name="android.hardware.camera.autofocus" />
Add this to your build.gradle (app) file:
repositories { jcenter() } dependencies { compile 'com.journeyapps:zxing-android-embedded:3.0.2@aar' compile 'com.google.zxing:core:3.2.0' }
Create a callback in your activity:
private BarcodeCallback callback = new BarcodeCallback() { @Override public void barcodeResult(BarcodeResult result) {
Oncreate ()
mBarcodeView = (BarcodeView) findViewById(R.id.barcode_view); // Choose only one!!! mBarcodeView.decodeSingle(callback); // Or mBarcodeView.decodeContinuous(callback);
onResume ()
mBarcodeView.resume();
Onpause ()
mBarcodeView.pause();
In your Activity XML layout add BarcodeView
<com.journeyapps.barcodescanner.BarcodeView android:id="@+id/barcode_view" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_centerVertical="true" android:layout_centerHorizontal="true"> </com.journeyapps.barcodescanner.BarcodeView>
Hope this helps!
Andres santiago
source share