ICode9

精准搜索请尝试: 精确搜索
首页?>?其他分享> 文章详细

android – ZXing条码扫描器在片段中的自定义布局

2019-09-30 10:35:19??阅读:10??来源: 互联网

标签:barcode-scanner?android?android-fragments?zxing


我在Android Studio上开发了this page的ZXing条码连续扫描仪.

我的应用build.gradle包括:

repositories {
    mavenCentral()

    maven {
        url "https://raw.github.com/embarkmobile/zxing-android-minimal/mvn-repo/maven-repository/"
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:23.0.1'
    compile files('src/main/jniLibs/scanditsdk-android-4.7.5.jar')
    compile files('src/main/jniLibs/httpclient-4.0.jar')

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

我的Fragment.xml的布局:




    

    

    


        

        

        

        
    


然后,我的Fragment代码如下所示:

public class CMCSMOFragment extends Fragment implements View.OnClickListener {

    private CompoundBarcodeView barcodeView;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        if (container == null) {
            return null;
        }

        View v;
        v = inflater.inflate(R.layout.cmcsmo_layout, container, false);

        barcodeView = (CompoundBarcodeView) v.findViewById(R.id.barcode_scanner);
        barcodeView.decodeContinuous(callback);

        return v;
    }

    private BarcodeCallback callback = new BarcodeCallback() {
        @Override
        public void barcodeResult(BarcodeResult result) {
            if (result.getText() != null) {
                barcodeView.setStatusText(result.getText());
            }

            //Do something with code result
        }

        @Override
        public void possibleResultPoints(List resultPoints) {
        }
    };
}

当我构建我的应用程序时,CompoundBarcodeView只显示带有ZXing文本的黑色视图:

Place a barcode inside the viewfinder rectangle to scan it.

编辑:

遵循列侬的建议,我曾使用zxing-minimum,但它不允许在肖像模式下工作:(.

我该怎么做才能解决这个问题?谢谢大家的帮助!

解决方法:

这很简单,ZXing的老板说只在onResume和onPause覆盖方法中添加以下代码:

@Override
public void onResume() {
    barcodeView.resume();
    super.onResume();
}

@Override
public void onPause() {
    barcodeView.pause();
    super.onPause();
}


标签:barcode-scanner,android,android-fragments,zxing

专注分享技术,共同学习,共同进步。侵权联系[admin#icode9.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有