Integrating Zxing Barcode scanner to my android app

眉间皱痕 提交于 2019-12-25 07:26:52

问题


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.


回答1:


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




回答2:


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());


                    }
                });
            }
        });



回答3:


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



来源:https://stackoverflow.com/questions/37807777/integrating-zxing-barcode-scanner-to-my-android-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!