I am using the following code for 2D-QR code decoder.
package com.test.rim;
import java.util.*;
import net.rim.device.api.barcodelib.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.Dialog;
import com.google.zxing.*;
final class BarcodeScanScreen extends MainScreen{
BarcodeScanScreen barcodeScanScreen;
BarcodeScanScreen(){
BarcodeDecoderListener listener = new BarcodeDecoderListener(){
public void barcodeDecoded( String rawText )
{
Dialog.alert(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{
BarcodeScanner scanner = new BarcodeScanner( decoder, listener );
scanner.getVideoControl().setDisplayFullScreen( true );
add( scanner.getViewfinder() );
scanner.startScan();
}catch (Exception e)
{
// Catch errors here
Dialog.alert("Error:" + e.getMessage());
}
}
}
To start this screen, I am firing the a code app.pushScreen(new BarcodeScanScreen());
on a button tap from its previous screen.
When I am running the code, the BarcodeScanScreen
starts properly and the scanning is also going on(as the red light of the device is blinking). As soon as I place the cam before any valid 2D-QR code, the blink stops. I think it means, any barcode is decoded successfully and therefore the scanner stops. But barcodeDecoded()
method is not fired as no alert massage is appear in the screen. What is the problem in my code?
I use this code in barcodeDecoded()
and it solves my prob.
app.invokeLater(new Runnable() {
public void run() {
try { javax.microedition.media.Manager.playTone(ToneControl.C4, 1000, 100);} catch (MediaException e) { }
app.popScreen(_barcodeScreen);
showDecoded(rawText);
}
});
_barcodeScreen.invalidate();