简体   繁体   English

在Fragment的布局中显示ZXING条码扫描器

[英]Displaying ZXING Barcode scanner in Fragment's Layout

I have an Activity called Scanner with two fragments each using 1/2 of the display. 我有一个名为Scanner的活动,其中有两个片段各自使用显示的1/2。 What I am trying to achieve is running a ZXING barcode scanner in the one fragment and display the scan results in the other fragment. 我要实现的目标是在一个片段中运行ZXING条形码扫描仪,并在另一个片段中显示扫描结果。

I am using callback to the activity to communicate between the two fragments. 我正在使用该活动的回调在两个片段之间进行通信。 Have tested that part with a button in one and a text view in the other. 用一个按钮和另一个文本视图测试了该部分。

The problem I am facing is that I cannot find a way (yet) to run the scanner only in the one fragment. 我面临的问题是,我还无法找到一种方法来仅在一个片段中运行扫描仪。 As soon as I initiate the scanner it uses the full display for the view finder. 启动扫描仪后,它将使用完整的显示屏显示取景器。

The scanners' first parameter is Activity and I suspect that might be where I am doing something wrong? 扫描仪的第一个参数是Activity,我怀疑这可能是我做错事情的地方了吗?

My Gradle: 我的摇篮:

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

The code to launch the scanner: 启动扫描器的代码:

    public void startScanner(Activity a,int cam){

    IntentIntegrator integrator = new IntentIntegrator(a);
    integrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE_TYPES);
    integrator.setPrompt("Scan");
    integrator.setCameraId(cam);
    integrator.setBeepEnabled(true);
    integrator.setBarcodeImageEnabled(false);
    integrator.initiateScan();
}

这种使用ZXING的方式只是调用他们的应用程序来进行扫描,这不是代码的一部分。

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

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