我想在BlackBerry Os 6中实现QR码阅读器。我在KB文章How to use the Barcode API的基础上尝试以下代码。
public class ScanScreen extends MainScreen implements BarcodeDecoderListener
{
private LabelField match;
private BarcodeScanner scanner;
public ScanScreen()
{
match = new LabelField("Scanning...");
add(match);
Vector supported = new Vector();
supported.addElement(BarcodeFormat.QR_CODE);
Hashtable hints = new Hashtable();
hints.put(DecodeHintType.POSSIBLE_FORMATS, supported);
hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
BarcodeDecoder decoder = new BarcodeDecoder(hints);
try
{
scanner = new BarcodeScanner(decoder, this);
add(scanner.getViewfinder());
scanner.startScan();
}
catch (Exception e)
{
e.printStackTrace();
match.setText("Exception");
invalidate();
}
}
public void barcodeDecoded(String rawText)
{
match.setText("Found: " + rawText);
invalidate();
}
public void close()
{
try
{
scanner.stopScan();
}
catch (Exception e)
{
e.printStackTrace();
}
super.close();
}
}
守则不起作用。 无法识别QR码。我尝试着重于不同的QR码。但它没有解码qrcodes.Also它没有抛出任何例外。请帮助我....
我尝试使用这些设备: BB珍珠9105和BB风暴9530
答案 0 :(得分:0)
请参阅以下链接中的示例。它将为您提供帮助
http://aliirawan-wen.blogspot.com/2011/05/barcode-scanner-for-blackberry-os-50.html
答案 1 :(得分:0)
我是BB开发的新手,但我注意到你将“this”作为decoderlistener参数传递,或许这会导致问题?
BarcodeDecoder decoder = new BarcodeDecoder(hints);
BarcodeDecoderListener decoderListener = new BarcodeDecoderListener()
{
public void barcodeDecoded(String rawText)
{
displayMessage(rawText);
}
};
try
{
scanner = new BarcodeScanner(decoder, decoderListener)
add(scanner.getViewfinder());
scanner.startScan();
}
catch (Exception e)
{
e.printStackTrace();
match.setText("Exception");
invalidate();
}
}