Search code examples
javaandroidzxingbarcode-scanner

Integrating Zxing Barcode scanner to my android app


I'm trying to integrate barcode scanner in my android app.

These are the things i have done:

1) i added core-3.2.1 module to my project. 2) added an activity

<uses-permission android:name="android.permission.CAMERA" />
<activity
android:name="com.google.zxing.client.android.CaptureActivity"
android:screenOrientation="landscape" >
</activity>

I'm getting that Cannot resolve symbol 'CaptureActivity'. What should i do more?

I have checked other stackoverflow posts but i'm unable to fix this.


Solution

  • You can add zxing library to your app via gradle dependency

    just add this to your build.gradle file

    compile 'com.google.zxing:core:3.2.1'
    compile 'com.journeyapps:zxing-android-embedded:3.0.3@aar'
    

    Now in your onCreate method of your activity , do the following

     IntentIntegrator scanIntegrator = new IntentIntegrator(MainActivity.this);
     scanIntegrator.setPrompt("Scan a Barcode");
     scanIntegrator.setBeepEnabled(true); 
     scanIntegrator.setOrientationLocked(true);
     scanIntegrator.setBarcodeImageEnabled(true);
     scanIntegrator.initiateScan();
    

    You can find a sample project here