OS 6 中黑莓 QR 码解码问题

发布于 2025-01-05 19:45:43 字数 1591 浏览 2 评论 0原文

我正在使用以下代码进行 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

像你 2025-01-12 19:45:43

我在 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();

I use this code in barcodeDecoded() and it solves my prob.

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();
多孤肩上扛 2025-01-12 19:45:43

您的代码看起来不错,所以我唯一能想到的是 Dialog.alert 未成功运行,因为您的 BarcodeScanScreen 无法在其顶部显示模式对话框 - 视频预览窗口不能有覆盖层。在显示警报之前,尝试停止扫描仪并从堆栈中弹出视频预览屏幕。

Your code looks fine so the only thing I can think of is that Dialog.alert does not run successfully because your BarcodeScanScreen 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.

北座城市 2025-01-12 19:45:43

问题是在获取 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
    }                   
}
};

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:

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

Do like this:

BarcodeDecoderListener listener =new BarcodeDecoderListener() 
{
public void barcodeDecoded(String rawText) 
{
    try 
    {           
        barcodeScanner.stopScan();
         Dialog.alert(rawText);
    } 
    catch (Exception e) 
    {
        //Catch the Exception
    }                   
}
};
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文