Question

I am trying to scan QR code with my code. My code is running fine with 5.0(Bold) and 7.1(Torch) OS phones. It is running fine with 7.1 and 5.0. but giving problem while running with 6.0 OS(Bold 9700). The problem is - "While trying to scan QR code, app scans the QR code but camera screen doesn't pop and it remains at the front. Event it is not able to hide by using Esc key". please help me to resolve the issue with os6.

Edit:

Code while opening camera screen for QR code scan:

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

code for closing screen is:

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

I am calling this code after scanning of QR code.

Was it helpful?

Solution 2

I have solved my same issue for os 6. After scanning of QR code, close all player and scanner connection.

You can use-

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

It is helpful to me. This will definitely help you.

OTHER TIPS

This is a problem with OS6 in some devices that has been asked before on this site. Last one was two days ago:
Blackberry OS6 camera wont shut down after capture

AFAIK there's no API to close the camera app, so it has to be done with key injection hacks, that are tricky because they need accurate timing and as CPUs are different in some models, and also because the camera app has a different design in some OSes.

So either you use JSR135 and use a renamed Zxing package to provide a camera view contained in your app, or just follow your approach but instead of closing the camera app you just bring to foreground your own app.

here is my code , it's working perfectly in OS 6.0 device 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);
    }

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top