BlackBerry os 6的QR码屏幕弹出问题

时间:2012-10-04 04:29:11

标签: blackberry camera screen qr-code blackberry-os6

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

修改

打开QR码扫描的相机屏幕时的代码:

    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); 
    } 
});

我在扫描QR码后调用此代码。

3 个答案:

答案 0 :(得分: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);
    }

}

答案 1 :(得分:1)

这是以前在本网站上询问过的某些设备中的OS6问题。最后一天是两天前:
Blackberry OS6 camera wont shut down after capture

AFAIK没有用于关闭相机应用程序的API,所以它必须通过关键注入黑客来完成,这很棘手,因为它们需要精确的计时,并且因为某些型号的CPU不同,而且因为相机应用程序有不同的一些操作系统中的设计。

因此,要么使用JSR135并使用重命名的Zxing软件包来提供应用中包含的相机视图,要么只是按照您的方法进行操作,而不是关闭相机应用程序,而只需将自己的应用程序置于前台。 / p>

答案 2 :(得分:1)

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

您可以使用 -

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

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