2012-02-20 148 views
1

我正在爲黑莓手機實現一個QR碼掃描儀,我正在使用ZXing庫來實現這一點。順便說一下,這是針對os 6+的。我遇到的問題是,有時,有時,當相機打開準備掃描時,設備將凍結並完全重新啓動...Zxing 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

首先看到的樣品演示名稱爲「** BarcodeScan演示**」從版本提供6.0以上; 然後你可以理解所有; – alishaik786 2012-02-21 04:38:27

+0

我按照演示和閱讀文章..因爲我說它工作95%的時間..我只是越來越奇怪崩潰 – 2012-02-21 17:12:15

+0

你在哪裏得到崩潰?我運行該示例演示,它沒有發生任何崩潰,並通過提供的演示創建了我自己的條形碼掃描演示;; – alishaik786 2012-02-22 03:56:27

回答