简体   繁体   English

将Zxing条形码扫描仪集成到我的android应用中

[英]Integrating Zxing Barcode scanner to my android app

I'm trying to integrate barcode scanner in my android app. 我正在尝试将条形码扫描仪集成到我的android应用中。

These are the things i have done: 这些是我所做的事情:

1) i added core-3.2.1 module to my project. 1)我添加了core-3.2.1模块到我的项目中。 2) added an activity 2)添加了一个活动

<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'. 我得到无法解析符号“ CaptureActivity”。 What should i do more? 我该怎么办?

I have checked other stackoverflow posts but i'm unable to fix this. 我检查了其他stackoverflow帖子,但无法解决此问题。

You can add zxing library to your app via gradle dependency 您可以通过gradle依赖关系将zxing库添加到您的应用中

just add this to your build.gradle file 只需将此添加到您的build.gradle文件

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 现在在您的活动的onCreate方法中,执行以下操作

 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 您可以在此处找到示例项目

make sure you use give dependencies in app.gradle file than use scanner view for scan barcode 确保您在app.gradle文件中使用给定依赖性,而不是使用扫描仪视图扫描条形码

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


                    }
                });
            }
        });

Make sure you have added module reference into your project. 确保已将模块引用添加到项目中。 1) New -> Import new Module -> Select your zxing library. 1)新建->导入新模块->选择您的zxing库。 Let the gradle build. 让gradle建立起来。

Then, Go to File -> Project Structure -> Select app under modules -> Go to Dependency tab -> add zxing module by clicking on green add button. 然后,转到文件->项目结构->在模块下选择应用程序->转到依赖项标签->通过单击绿色添加按钮添加zxing模块。

Rebuild your project 重建项目

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM