Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Forums Advisor I
Posts: 501
Registered: ‎03-01-2013
My Device: BlackBerry Z10

Problem in QR Code..

Scanning is done bt after that it does not redirect me to the contained information..Can any1 help me to figure out what is the problm in this..Its urgent im trying from past few days bt didnt get the solution yet...

Thanks in advance,....

 

class UiAppScreen extends MainScreen
{
    private FullScreen _barcodeScreen;
    private static UiApp _app;
    
    public UiAppScreen()
    {
        BarcodeDecoderListener listener = new BarcodeDecoderListener()
        {
            public void barcodeDecoded(final String rawText)
            {

                // First pop the viewfinder screen off of the stack so we can see
                // the main app
                _app.invokeLater(new Runnable()
                {
                    public void run()
                    {
                        _app.popScreen(_barcodeScreen);

                    }
                });

 

final StringBuffer message = new StringBuffer("Would you like to open the browser pointing to \"");
                message.append(rawText);
                message.append("\"?");
                System.out.println(message.toString());
                _barcodeScreen.invalidate();

 

_app.invokeLater(new Runnable()
                {
                    public void run()
                    
                    {
                        if (Dialog.ask(Dialog.D_YES_NO, message.toString()) == Dialog.YES)
                        {
                                
                            UiApplication.getUiApplication().pushScreen(new NewScreen(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
        {
            MainScreen screen = new MainScreen();
            BarcodeScanner scanner = new BarcodeScanner( decoder, listener );
            scanner.getVideoControl().setDisplayFullScreen( true );
            screen.add( scanner.getViewfinder() );
            UiApplication.getUiApplication().pushScreen( screen );
            scanner.startScan();
        }
        catch (Exception e)
        {
            System.out.println(e);
        }

    }
    

}

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Problem in QR Code..

And whereabouts in your code does it actually get to?  What happens when you debug this?  Which statement is not doing what you expect it to do?

Forums Advisor I
Posts: 501
Registered: ‎03-01-2013
My Device: BlackBerry Z10

Re: Problem in QR Code..

After scanning the bar code,it doesnot redirect me to the contained data neither it asks

"Would you like to open the browser pointing to"??

 

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Problem in QR Code..

Your answer is from the User perspective.  Can you look at my questions again from a developer perspective?

 

As an example on interesting idea would be to put a break point at the start of your barcodeDecoded() method and then step through the lines that are executed. 

 

Perhaps one of these will help you do this?

http://supportforums.blackberry.com/t5/Java-Development/How-Do-I-Debug-on-a-Live-Device/ta-p/446842

http://supportforums.blackberry.com/t5/Java-Development/Debug-an-application-running-on-a-live-Black...

Forums Advisor I
Posts: 501
Registered: ‎03-01-2013
My Device: BlackBerry Z10

Re: Problem in QR Code..

Finally i got the solution...

 

BarcodeDecoderListener listener = new BarcodeDecoderListener(){
              
              private Runnable _restart = new Runnable() {
                   public void run() {
                       try{
                           scanner.startScan();
                       }
                       catch(Exception e)
                       {
                           
                       }
                   }
               };
              
                public void barcodeDecoded(String rawText )
                {
                    System.out.println("Found: " + rawText);
                    invalidate();

                    
                    synchronized (UiApplication.getEventLock()) {
                        
                  
                    
                    
                        Dialog dialog = new Dialog("Would you like to open the browser pointing to \""+rawText+"\"?", new String[]{"Ok","Cancel"}, new int[]{Dialog.D_OK,Dialog.CANCEL},null, null);
                        UiApplication.getUiApplication().pushScreen(dialog);
                        
                        if(dialog.OK==Dialog.D_OK)
                            {
                                    
                                UiApplication.getUiApplication().pushScreen(new NewScreen(rawText));
                            }
                        else if(Dialog.ask(dialog.CANCEL,rawText.toString())==Dialog.CANCEL)
                        {
                            try
                            {
                                scanner.stopScan();
                                
                            }
                            catch(Exception e){}
                        }
                    }

 

 

Bt there is a small problm in this as soon as the qr code is scanned it directly opens the link..I want that a dialob box will open that will ask yes or no option,i have made Dialog class above.....Can any1 plz help me to solve this problm
                   

 

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Problem in QR Code..

Perhaps you could document the solution so that the next person who has a similar problem has some hints as to how to solve the problem? 

 

Returning to the problem you are now describing, I don't see anything in this code that opens a link so I'm not sure where that happens. 

 

It would be helpful when you are describing a problem you give us all the related informaiton and nothing that is unrelated.  In this case we appear to be missing the code that does the link and you have given us a _restart Runnable that is never used.  In addition it would be useful if you described the processing that your program does - which if the statements in your code are actually executed and what happens when they are. 

 

I have some general comments that may not be directly related to this problem but will help you code for BlackBerry in general anyway. 

 

1) You need to be very careful when you use

synchronized (UiApplication.getEventLock()) ...

Especially if you have a blocking Dialog within this.  Using this you are locking the Event Thread.  So any other processing will have to wait till this is finished.  You can using this deadlock yourself by issuing something like Dialog.ok, which itself requires access to the Event Thread.  This is my least favourite method of getting on the Event Thread and one I would urge you to use with caution.

 

2) The method pushScreen is non blocking.  If you expect to test a result of a screen after it has finished, then you should look at push Modal.   

 

3) Can you please use standard English in your posts so that non Emglish speakers at least have some chance of being able to read what you write.

 

4) In general I suggest you use the debugger to step through your code and work out which of your instructions is not working as you require it.  Then you can focus the problem down. 

 

Finally, this page has some useful hints that should help you ask your questions in a way that makes it easier for us to answer them.

http://www.catb.org/esr/faqs/smart-questions.html

Forums Advisor I
Posts: 501
Registered: ‎03-01-2013
My Device: BlackBerry Z10

Re: Problem in QR Code..

Hi Peter,

I donot understand whether you want me to post the whole code or what??

I just have posted the code for BarCodeListener,the rest is same as above...

Using instance of Dialog class it redirects me to the contained link

.But my problem is :

1)As soon as the scanner scans the QR Code it directly points me to the link,i want that when i click Ok button only then i redirect me to that link.

2)When i press Ok ,I should be at the contained link ank when Cancel then at the same page

 

I hope i have not mistaken this time..

Highlighted
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Problem in QR Code..

"As soon as the scanner scans the QR Code it directly points me to the link"

 

I want you to find out exactly which statements in your code are executed to cause this to happen.  I don't mind how you find out, but I suggest the easiest way is to debug on device - instructions for debugging on device given previously.  Once you have determined exactly what statements are executed, then you can review these and see which statement is not working as you expect it too.  OK?