0

自分のコードで 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コードを読み取った後、このコードを呼び出しています。

4

3 に答える 3

1

OS 6 で同じ問題を解決しました。QR コードをスキャンした後、すべてのプレーヤーとスキャナーの接続を閉じます。

あなたが使用することができます-

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

それは私にとって役に立ちます。これは間違いなくあなたを助けます。

于 2012-10-05T04:36:28.573 に答える
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 の問題です。最後の 1 つは 2 日前:
キャプチャ後に Blackberry OS6 カメラがシャットダウンしない

私の知る限り、カメラ アプリを閉じる API はありません。そのため、キー インジェクション ハックを使用して行う必要があります。正確なタイミングが必要であり、一部のモデルでは CPU が異なるため、カメラ アプリの設計が一部のモデルで異なるため、注意が必要です。 OS。

したがって、JSR135を使用し、名前を変更した Zxing パッケージを使用してアプリに含まれるカメラ ビューを提供するか、アプローチに従って、カメラ アプリを閉じる代わりに独自のアプリをフォアグラウンドにするだけです。

于 2012-10-04T14:04:28.440 に答える