我正在为黑莓设备实施QR码扫描程序,我正在使用ZXing库这样做。顺便说一句,这是针对os 6+的。我遇到的问题是,有时候,有时候,当相机打开准备扫描时,设备会冻结并完全重启......
否则它大部分时间都可以工作,我可以扫描和解码qr代码等。但似乎偶尔会感觉像是无缘无故崩溃。我不知道它是用相机还是我的代码中的东西,但我会提供代码。
public void scanBarcode() {
// First we create a hashtable to hold all of the hints that we can
// give the API about how we want to scan a barcode to improve speed
// and accuracy.
Hashtable hints = new Hashtable();
// The first thing going in is a list of formats. We could look for
// more than one at a time, but it's much slower.
Vector formats = new Vector();
formats.addElement(BarcodeFormat.QR_CODE);
hints.put(DecodeHintType.POSSIBLE_FORMATS, formats);
// We will also use the "TRY_HARDER" flag to make sure we get an
// accurate scan
hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
// We create a new decoder using those hints
BarcodeDecoder decoder = new BarcodeDecoder(hints);
// Finally we can create the actual scanner with a decoder and a
// listener that will handle the data stored in the barcode. We put
// that in our view screen to handle the display.
try {
_scanner = new BarcodeScanner(decoder, new MyBarcodeDecoderListener());
_barcodeScreen = new MyBarcodeScannerViewScreen(_scanner);
} catch (Exception e) {
return;
}
// If we get here, all the barcode scanning infrastructure should be set
// up, so all we have to do is start the scan and display the viewfinder
try {
_scanner.stopScan();
_scanner.getPlayer().start();
_scanner.startScan();
UiApplication.getUiApplication().pushScreen(_barcodeScreen);
} catch (Exception e) {
}
}
/***
* MyBarcodeDecoderListener
* <p>
* This BarcodeDecoverListener implementation tries to open any data encoded
* in a barcode in the browser.
*
* @author PBernhardt
*
**/
private class MyBarcodeDecoderListener implements BarcodeDecoderListener {
public void barcodeDecoded(final String rawText) {
//UiApplication.getUiApplication().popScreen(UiApplication.getUiApplication().getActiveScreen());
UtilityDecoder.saveToHistory(rawText);
try {
UtilityDecoder.distributeBarcode(rawText);
} catch (PIMException e) {
}
}
}
当我点击工具栏上的按钮时,我基本上会调用scanBarcode()。
有人能告诉我我的代码是问题,还是设备或其他什么?提前感谢您提供的任何帮助!
答案 0 :(得分:1)
试试这个链接:
Scan Any Type of Barcode Image which Supports Blackberry
请参阅此forun链接并查看该链接的讨论。当然,您将获得条形码扫描的整体概念,您还将获得在5.0版本中实现QRCode