gpt4 book ai didi

java - ZXing二维码扫描黑莓崩溃

转载 作者:太空宇宙 更新时间:2023-11-04 08:21:59 29 4
gpt4 key购买 nike

我正在为黑莓设备实现 QR 码扫描仪,并使用 ZXing 库来实现此目的。顺便说一句,这是针对 os 6+ 的。我遇到的问题是,有时,仅有时,当相机打开准备扫描时,设备会卡住并完全重新启动...

否则它在大多数情况下都可以工作,我可以扫描和解码二维码等。但是,它似乎偶尔会无缘无故地崩溃。我不知道这是相机的问题还是我的代码中的问题,但我会提供代码。

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()。

谁能告诉我是我的代码有问题,还是设备有问题,还是其他什么问题?预先感谢您提供的任何帮助!

最佳答案

尝试此链接:

Scan Any Type of Barcode Image which Supports Blackberry

请参阅此论坛链接并查看该链接的讨论。当然,您将获得条码扫描的整体概念,并且您还将获得5.0版本中QRCode的实现

Any type of Barcode scaning in 5.0

关于java - ZXing二维码扫描黑莓崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9364669/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com