Codenameone codeScanner没有';当它';它与我的应用程序一起使用

Codenameone codeScanner没有';当它';它与我的应用程序一起使用,codenameone,Codenameone,我的代码扫描器有问题,我在应用程序中使用这个库来扫描条形码。我在安卓应用程序上工作,我尝试扫描128码格式的代码 public class ScanQr extends Form { final Container cnt = this; public ScanQr(Form parent){ this.setLayout(new BoxLayout(BoxLayout.Y_AXIS)); ButtonGroup bg = new ButtonGroup(); final

我的代码扫描器有问题,我在应用程序中使用这个库来扫描条形码。我在安卓应用程序上工作,我尝试扫描128码格式的代码

public class ScanQr extends Form {
final Container cnt = this;
public ScanQr(Form parent){
    this.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
    ButtonGroup bg = new ButtonGroup();
    final RadioButton qr = new RadioButton("QR Code");
    final RadioButton bar = new RadioButton("Bar Code");
    bg.add(qr);
    bg.add(bar);
    this.addComponent(new Label("Code Type"));
    this.addComponent(qr);
    this.addComponent(bar);

    Button scanBtn = new Button("Scan Code");
    scanBtn.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {

            if(qr.isSelected()){
                CodeScanner.getInstance().scanQRCode(new ScanResult() {
                    public void scanCompleted(String contents, String formatName, byte[] rawBytes) {
                        //barCode.setText("Bar: " + contents);
                        cnt.addComponent(new Label(contents));
                        cnt.revalidate();
                    }

                    public void scanCanceled() {
                        cnt.addComponent(new Label("cancelled"));
                    }

                    public void scanError(int errorCode, String message) {
                        cnt.addComponent(new Label("err " + message));
                    }
                });
            }else{
                CodeScanner.getInstance().scanBarCode(new ScanResult() {
                    public void scanCompleted(String contents, String formatName, byte[] rawBytes) {
                        //barCode.setText("Bar: " + contents);
                        cnt.addComponent(new Label(contents));
                        cnt.revalidate();
                    }

                    public void scanCanceled() {
                        cnt.addComponent(new Label("cancelled"));
                    }

                    public void scanError(int errorCode, String message) {
                        cnt.addComponent(new Label("err " + message));
                    }
                });        
            }
        }

    });
    if (CodeScanner.isSupported()) {
        this.addComponent(scanBtn);
    } else {
        this.addComponent(new SpanLabel("Sorry.  Codescanner not supported on this platform"));
    }
}
}

首先,它安装条形码扫描仪+简单如果它没有安装,那么当这个应用程序与我的应用程序一起使用时,它会花费很多时间来查找和显示条形码上扫描的信息,或者它什么也找不到,但当我只单独使用条形码扫描仪+简单时,它工作得非常好,我没有任何问题


我不明白问题出在哪里,因为我使用的是同一个codescanner应用程序,但在两种不同的上下文中,分别是单独启动时和与我的应用程序一起启动时。

您需要尝试缩小扫描的类型范围以获得更好的结果,例如,在调用扫描之前的某个时间执行此操作:

Display.getInstance().setProperty("android.scanTypes", "CODE_128");