OS 6 中黑莓 QR 码解码问题
我正在使用以下代码进行 2D-QR 码解码器。
package com.test.rim;
import java.util.*;
import net.rim.device.api.barcodelib.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.Dialog;
import com.google.zxing.*;
final class BarcodeScanScreen extends MainScreen{
BarcodeScanScreen barcodeScanScreen;
BarcodeScanScreen(){
BarcodeDecoderListener listener = new BarcodeDecoderListener(){
public void barcodeDecoded( String rawText )
{
Dialog.alert(rawText);
}
};
Hashtable hints = new Hashtable(1);
Vector formats = new Vector(1);
formats.addElement(BarcodeFormat.QR_CODE);
hints.put(DecodeHintType.POSSIBLE_FORMATS, formats);
BarcodeDecoder decoder = new BarcodeDecoder( hints );
try{
BarcodeScanner scanner = new BarcodeScanner( decoder, listener );
scanner.getVideoControl().setDisplayFullScreen( true );
add( scanner.getViewfinder() );
scanner.startScan();
}catch (Exception e)
{
// Catch errors here
Dialog.alert("Error:" + e.getMessage());
}
}
}
为了启动此屏幕,我在上一个屏幕上点击按钮时触发代码 app.pushScreen(new BarcodeScanScreen());
。
当我运行代码时,BarcodeScanScreen
正常启动,并且扫描也在进行(因为设备的红灯闪烁)。一旦我将摄像头放在任何有效的 2D-QR 码之前,闪烁就会停止。我认为这意味着,任何条形码都已成功解码,因此扫描仪停止。但是 barcodeDecoded()
方法不会被触发,因为屏幕上没有出现警报消息。我的代码有什么问题?
I am using the following code for 2D-QR code decoder.
package com.test.rim;
import java.util.*;
import net.rim.device.api.barcodelib.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.Dialog;
import com.google.zxing.*;
final class BarcodeScanScreen extends MainScreen{
BarcodeScanScreen barcodeScanScreen;
BarcodeScanScreen(){
BarcodeDecoderListener listener = new BarcodeDecoderListener(){
public void barcodeDecoded( String rawText )
{
Dialog.alert(rawText);
}
};
Hashtable hints = new Hashtable(1);
Vector formats = new Vector(1);
formats.addElement(BarcodeFormat.QR_CODE);
hints.put(DecodeHintType.POSSIBLE_FORMATS, formats);
BarcodeDecoder decoder = new BarcodeDecoder( hints );
try{
BarcodeScanner scanner = new BarcodeScanner( decoder, listener );
scanner.getVideoControl().setDisplayFullScreen( true );
add( scanner.getViewfinder() );
scanner.startScan();
}catch (Exception e)
{
// Catch errors here
Dialog.alert("Error:" + e.getMessage());
}
}
}
To start this screen, I am firing the a code app.pushScreen(new BarcodeScanScreen());
on a button tap from its previous screen.
When I am running the code, the BarcodeScanScreen
starts properly and the scanning is also going on(as the red light of the device is blinking). As soon as I place the cam before any valid 2D-QR code, the blink stops. I think it means, any barcode is decoded successfully and therefore the scanner stops. But barcodeDecoded()
method is not fired as no alert massage is appear in the screen. What is the problem in my code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我在
barcodeDecoded()
中使用此代码,它解决了我的问题。I use this code in
barcodeDecoded()
and it solves my prob.您的代码看起来不错,所以我唯一能想到的是
Dialog.alert
未成功运行,因为您的BarcodeScanScreen
无法在其顶部显示模式对话框 - 视频预览窗口不能有覆盖层。在显示警报之前,尝试停止扫描仪并从堆栈中弹出视频预览屏幕。Your code looks fine so the only thing I can think of is that
Dialog.alert
does not run successfully because yourBarcodeScanScreen
cannot display a modal dialog on top of it - the video preview window cannot have an overlay. Try stopping the scanner and popping the video preview screen off the stack before displaying your alert.问题是在获取 BarcodeDecoderListener 中的数据后,您没有停止扫描;
首先看黑莓提供的示例代码,示例名称为BarcodeDemo;
在您的代码中,不要这样做:
这样做:
The Problem is You are not stop the scanning after getting the data in BarcodeDecoderListener;
First see the sample code provided by the blackberry sample name BarcodeDemo;
In your code, instead of Doing this:
Do like this: