2012-02-14 97 views
0

我正在使用下面的代码为2D-QR码解码器。黑莓QR码解码概率在操作系统6

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()方法没有被触发,因为没有任何警报消息出现在屏幕上。我的代码中有什么问题?

+0

您是否测试过黑莓样本提供的示例代码?首先测试Blackberry Samples提供的BarcodeDemo;当您在BarcodeListener中找到数据时,您不会停止扫描; – alishaik786 2012-02-15 06:23:59

回答

1

我使用barcodeDecoded()此代码,它解决了我的概率。

app.invokeLater(new Runnable() { 
        public void run() { 
         try { javax.microedition.media.Manager.playTone(ToneControl.C4, 1000, 100);} catch (MediaException e) { } 
         app.popScreen(_barcodeScreen); 
         showDecoded(rawText); 
       } 
      }); 
      _barcodeScreen.invalidate(); 
+0

也可以使用: app.invokeLater(new Runnable(){ public void run(){try {javax.microedition.media.Manager.playTone(ToneControl.C4,1000,100);} catch(MediaException e) {} app.popScreen(_barcodeScreen); _barcodeScreen.invalidate(); showDecoded(rawText); } }); – AnkitRox 2012-09-28 13:20:04

0

您的代码看起来很好,所以我能想到的唯一的事情就是Dialog.alert未成功运行,因为你的BarcodeScanScreen无法显示在它上面的一个模式对话框 - 视频预览窗口不能有重叠。尝试停止扫描仪并在显示警报之前将视频预览屏幕弹出堆栈。

+0

我尝试通过此代码发出声音:try {javax.microedition.media.Manager.playTone(ToneControl.C4,1000,100);} catch(MediaException e){}}但没有声音。 – 2012-02-14 14:16:43

+0

您是否尝试过在'barcodeDecoded'上放置一个断点,然后运行调试程序以查看它是否实际被调用? – donturner 2012-02-14 14:20:24

+0

dev_android,使用** Alert.startAudio(new short [] {1046,200},100); **创建嘟嘟声。 – AnkitRox 2012-09-28 13:16:32

0

问题是你没有在获取数据BarcodeDecoderListener后停止扫描;

首先看黑莓样本名称提供的样本代码BarcodeDemo;

在你的代码,而不是这样做:

BarcodeDecoderListener listener = new BarcodeDecoderListener() 
{ 
    public void barcodeDecoded(String rawText) 
    { 
     Dialog.alert(rawText); 
    } 
}; 

这样做:

BarcodeDecoderListener listener =new BarcodeDecoderListener() 
{ 
public void barcodeDecoded(String rawText) 
{ 
    try 
    {   
     barcodeScanner.stopScan(); 
     Dialog.alert(rawText); 
    } 
    catch (Exception e) 
    { 
     //Catch the Exception 
    }     
} 
};