0

我正在尝试用我的代码扫描 QR 码。我的代码在 5.0(Bold) 和 7.1(Torch) OS 手机上运行良好。它在 7.1 和 5.0 中运行良好。但在运行 6.0 OS(Bold 9700)时出现问题。问题是 - “在尝试扫描 QR 码时,应用程序扫描 QR 码但相机屏幕没有弹出并且它仍然在前面。事件它无法使用 Esc 键隐藏”。请帮我解决os6的问题。

编辑:

打开相机屏幕进行二维码扫描时的代码:

    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 QR code. We put
    // that in our view screen to handle the display.
    try {
        _scanner = new BarcodeScanner(decoder, new LeadQRcodeDecoderListener());
        _QRcodeScreen = new LeadQRcodeScannerViewScreen(_scanner);

        // If we get here, all the QR code scanning infrastructure should be set
        // up, so all we have to do is start the scan and display the viewfinder
        _scanner.startScan();
        UiApplication.getUiApplication().pushScreen(_QRcodeScreen);
    }
    catch (Exception e) {
        e.printStackTrace();
        return;
    }

关闭屏幕的代码是:

UiApplication.getUiApplication().invokeLater(new Runnable() { 
    public void run() { 
        UiApplication.getUiApplication().popScreen(_QRcodeScreen); 
    } 
});

我在扫描二维码后调用此代码。

4

3 回答 3

1

这是我的代码,它在OS 6.0 设备 9830中运行良好

     /**
      * First Invoke the QR Scanner 
      */
     ViewFinderScreen _viewFinderScreen = 
          new ViewFinderScreen(ShoopingCartScreen.this); // ShoopingCartScreen.this Current Screen Object 
     UiApplication.getUiApplication().pushScreen(_viewFinderScreen);

package com.application.qrScanner;
import java.util.Hashtable;
import java.util.Vector;

import javax.microedition.media.MediaException;
import javax.microedition.media.Player;
import javax.microedition.media.control.VideoControl;

import net.rim.device.api.barcodelib.BarcodeDecoder;
import net.rim.device.api.barcodelib.BarcodeDecoderListener;
import net.rim.device.api.barcodelib.BarcodeScanner;
import net.rim.device.api.io.Base64InputStream;
import net.rim.device.api.io.http.HttpDateParser;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.Keypad;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.container.MainScreen;

import com.application.data.ShoopingCartObj;
import com.application.global.Global;
import com.application.log.Log;
import com.application.main.MessageScreen;
import com.application.main.orderDetail.orderSection.InputPopUpScreen;
import com.application.main.shoopingSection.ShoopingCartScreen;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.DecodeHintType;


public class ViewFinderScreen extends MainScreen 
{
    private BarcodeScanner _scanner;
    private short _frequency = 1046;
    private short _duration = 200;
    private int _volume = 100;
    private VideoControl vc;
    private ButtonField _btnCancel;
    private ShoopingCartScreen _shoopingCartScreen;

    /**
     * Creates a new ViewFinderScreen object
     */
    public ViewFinderScreen(ShoopingCartScreen _shoopingCartScreen)
    {

        this._shoopingCartScreen = _shoopingCartScreen;

        _btnCancel = new ButtonField("Cancel" , ButtonField.USE_ALL_WIDTH)
        {
            protected boolean navigationClick(int status, int time) 
            {
                fieldChangeNotify(1);
                return true;
            }
        };

        _btnCancel.setChangeListener(new FieldChangeListener() 
        {

            public void fieldChanged(Field field, int context) 
            {
                stopScan();
                UiApplication.getUiApplication().popScreen(ViewFinderScreen.this);

            }
        });

        // Initialize Hashtable used to inform the scanner how to
        // recognize the QR code format.
        Hashtable hints = new Hashtable();
        Vector formats  = new Vector(1);
        formats.addElement(BarcodeFormat.QR_CODE);
        hints.put(DecodeHintType.POSSIBLE_FORMATS, formats);

        // Initialize the BarcodeDecoder
        BarcodeDecoder decoder = new BarcodeDecoder(hints);

        // Create a custom instance of a BarcodeDecoderListener to pop the
        // screen and display results when a QR code is recognized.
        BarcodeDecoderListener decoderListener = new BarcodeDecoderListener()
        {
            /**
             * @see BarcodeDecoderListener#barcodeDecoded(String)
             */
            public void barcodeDecoded(String rawText)
            {
                try {

                    String encoded = rawText;
                    byte[] decoded = Base64InputStream.decode( encoded );

                    rawText  = new String(decoded);
                    System.out.println( new String( decoded ) );
                }
                catch (Throwable t) {

                    System.out.println( "Unable to decode string: " + t.getMessage() );
                }

                displayMessage(rawText);
                ViewFinderScreen.this. _shoopingCartScreen.beep();
            }
        };

        try
        {
            // Initialize the BarcodeScanner object and add the associated
            // view finder.                
            _scanner = new BarcodeScanner(decoder, decoderListener);

            vc = _scanner.getVideoControl();
            vc.setDisplayFullScreen(true);


            add(_scanner.getViewfinder());

            setStatus(_btnCancel);   
        }
        catch(Exception e)
        {
            displayMessage("Initilize Scanner: " + e.getMessage());
        }   

        startScan();
    }           

    /**
     * Informs the BarcodeScanner that it should begin scanning for QR Codes
     */
    public void startScan()
    {
        try
        {

            _scanner.startScan();
        }
        catch(MediaException me)
        {
            displayMessage(" Start Scan Error: " + me.getMessage());
        }
    }

    public void stopScan()
    {
        try 
        {
            Player p = _scanner.getPlayer() ;
            if(p != null)
            {
                p.stop();
                p.deallocate();
                p.close();
            }   
        } 
        catch (Exception e) 
        {
            MessageScreen.msgDialog("Exception in Stop Scanning "+e.toString());
        }
    } 

    /**
     * Pops the ViewFinderScreen and displays text on the main screen
     * 
     * @param text Text to display on the screen
     */
    private void displayMessage(final String text)
    {

        Log.d("QR Code String ", text);

        UiApplication.getUiApplication().invokeLater(new Runnable()
        {
            public void run()
            {
                stopScan();


            }

        });
    }


    protected boolean keyDown(int keycode, int time) 
    {
        if (Keypad.key(keycode) == Keypad.KEY_ESCAPE) 
        {
            stopScan();
            return true;
        }
        return super.keyDown(keycode, time);
    }

}
于 2012-10-04T07:19:39.593 回答
1

这是之前在本网站上询问过的某些设备中 OS6 的问题。上一个是两天前:
Blackberry OS6 相机在拍摄后不会关闭

AFAIK 没有关闭相机应用程序的 API,因此必须通过密钥注入黑客来完成,这很棘手,因为它们需要准确的时间,并且由于某些型号的 CPU 不同,而且相机应用程序在某些方面具有不同的设计操作系统。

因此,您要么使用JSR135并使用重命名的 Zxing 包来提供包含在您的应用程序中的相机视图,或者只是按照您的方法而不是关闭相机应用程序,而是将您自己的应用程序置于前台。

于 2012-10-04T14:04:28.440 回答
1

我已经解决了 os 6 的相同问题。扫描 QR 码后,关闭所有播放器和扫描仪连接。

您可以使用-

if (_scanner != null && _scanner.getPlayer() != null) {
    _scanner.getPlayer().close();
}

这对我很有帮助。这肯定会对你有所帮助。

于 2012-10-05T04:36:28.573 回答