问题
I have used codenameone codescanner library to read bar code. It uses third party scanner which if used separately works fine and is quick to read the bar code. But using codenameone app, the same scanner is too slow(most of the time unable to scan). I have tested it in samsung devices and few other devices. The outcome is not so good. How can I enhance the scanner?
code:
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() {
System.out.println("cancelled");
}
public void scanError(int errorCode, String message) {
System.out.println("err " + message);
}
});
One more thing, some time it reads the bar code but gives different code rather than those written below the code. for eg I was scanning IMEI no of mobile device, it has more than 15-20 numbers, but the scanner gives the 5-6 digit numbers other than those IMEI numbers. What happened here?
you can see the problem in the video... https://youtu.be/xCtx0ZlFH0U
回答1:
Try setting the explicit code type you are trying to read e.g.:
Display.getInstance().setProperty("android.scanTypes", "UPC_E");
You can see the list of code types here.
Alternatively try the little monkey QR code library (it works with barcodes too) it's often better on Android.
来源:https://stackoverflow.com/questions/41886104/bar-code-scanner-is-too-slow-to-read-the-code