manish reddy
manish reddy

Reputation: 177

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.

Upvotes: 0

Views: 2894

Answers (3)

Mithun Sarker
Mithun Sarker

Reputation: 4023

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

Upvotes: 3

Dexto
Dexto

Reputation: 1201

Make sure you have added module reference into your project. 1) New -> Import new Module -> Select your zxing library. Let the gradle build.

Then, Go to File -> Project Structure -> Select app under modules -> Go to Dependency tab -> add zxing module by clicking on green add button.

Rebuild your project

Upvotes: 0

Divyesh Boda
Divyesh Boda

Reputation: 258

make sure you use give dependencies in app.gradle file than use scanner view for scan barcode

dependencies {
    compile 'me.dm7.barcodescanner:zxing:1.8.3'
} 

ZXingScannerView mScannerView = new ZXingScannerView(this);
        Handler handlerThread = new Handler();
        handlerThread.post(new Runnable() {
            @Override
            public void run() {
                mScannerView.setResultHandler(new ZXingScannerView.ResultHandler() {
                    @Override
                    public void handleResult(Result result) {

                        Log.e(TAG, result.getText());


                    }
                });
            }
        });

Upvotes: 2

Related Questions