codeScanner 在与我的应用程序一起使用时不起作用
The codeScanner doesn't work when it's used with my application
我的代码扫描器有问题,我在我的应用程序中使用这个库 https://github.com/codenameone/cn1-codescan 来扫描条形码。我在 android 应用程序上工作,我尝试扫描 code_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"));
}
}
}
首先它会安装 Barcode Scanner+ Simple 如果它没有安装然后当这个应用程序与我的应用程序一起使用时,它需要很多时间来查找和显示条形码上扫描的信息或者它找不到任何东西但当我只是单独使用 Barcode Scanner+ Simple,它工作得很好,我没有任何问题。
我不明白问题出在哪里,因为我使用相同的代码扫描器应用程序,但在 2 个不同的上下文中,当它单独启动时以及当它与我的应用程序一起启动时。
您需要尝试缩小扫描的类型以获得更好的结果,例如在调用扫描之前执行此操作:
Display.getInstance().setProperty("android.scanTypes", "CODE_128");
我的代码扫描器有问题,我在我的应用程序中使用这个库 https://github.com/codenameone/cn1-codescan 来扫描条形码。我在 android 应用程序上工作,我尝试扫描 code_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"));
}
}
}
首先它会安装 Barcode Scanner+ Simple 如果它没有安装然后当这个应用程序与我的应用程序一起使用时,它需要很多时间来查找和显示条形码上扫描的信息或者它找不到任何东西但当我只是单独使用 Barcode Scanner+ Simple,它工作得很好,我没有任何问题。
我不明白问题出在哪里,因为我使用相同的代码扫描器应用程序,但在 2 个不同的上下文中,当它单独启动时以及当它与我的应用程序一起启动时。
您需要尝试缩小扫描的类型以获得更好的结果,例如在调用扫描之前执行此操作:
Display.getInstance().setProperty("android.scanTypes", "CODE_128");