This following class Scans Any type of the Barcode Image which is supports in Blackberry;
Only For Using Version >=6.0
-----------------------------------LoadingScreen.java-------------------------------------
public class LoadingScreen extends MainScreen implements FieldChangeListener
{
public BarCodeScannerScreen codeScannerView;
private LabelField showMessage;
private ButtonField scan;
private Font font;
private short _frequency = 1046;
private short _duration = 200;
private int _volume = 100;
public LoadingScreen()
{
setTitle("BAR CODE Demo");
font=Font.getDefault().derive(Font.BOLD|Font.ITALIC, 20);
createGUI();
}
private void createGUI()
{
LabelField label=new LabelField("Click The Button To Scan", Field.NON_FOCUSABLE|Field.FIELD_LEADING);
label.setFont(font);
label.setPadding(10, 0, 10, 0);
add(label);
scan=new ButtonField("Scan BARCODE", FIELD_HCENTER);
scan.setFont(font);
scan.setChangeListener(this);
add(scan);
showMessage=new LabelField();
showMessage.setFont(font);
showMessage.setPadding(10, 0, 0, 0);
add(showMessage);
}
public void fieldChanged(Field field, int context)
{
if(field==scan)
{
codeScannerView=new BarCodeScannerScreen(this);
UiApplication.getUiApplication().pushScreen(codeScannerView);
codeScannerView.startScan();
}
}
protected void beepSound()
{
UiApplication.getUiApplication().invokeLater(new Runnable()
{
public void run()
{
Alert.startAudio(new short[]{_frequency, _duration}, _volume);
}
});
}
public void displayMessage(String text)
{
synchronized (Application.getEventLock())
{
UiApplication.getUiApplication().popScreen(codeScannerView);
showMessage.setText(text);
}
}
protected boolean onSavePrompt()
{
return true;
}
}
-----------------------------------BarCodeScannerScreen .java-------------------------------------
public class BarCodeScannerScreen extends MainScreen
{
private LoadingScreen qrCodeScanner;
private BarcodeScanner barcodeScanner;
public BarCodeScannerScreen(LoadingScreen loadingScreen)
{
this.qrCodeScanner=loadingScreen;
Hashtable hashtable=new Hashtable();
Vector formats=new Vector(10);
formats.addElement(BarcodeFormat.QR_CODE);//In Blackberry These are the supported Formats
formats.addElement(BarcodeFormat.PDF_417);
formats.addElement(BarcodeFormat.CODE_128);
formats.addElement(BarcodeFormat.CODE_39);
formats.addElement(BarcodeFormat.DATA_MATRIX);
formats.addElement(BarcodeFormat.EAN_13);
formats.addElement(BarcodeFormat.EAN_8);
formats.addElement(BarcodeFormat.ITF);
formats.addElement(BarcodeFormat.UPC_A);
formats.addElement(BarcodeFormat.UPC_E);
hashtable.put(DecodeHintType.POSSIBLE_FORMATS, formats);
BarcodeDecoder barcodeDecoder=new BarcodeDecoder(hashtable);
BarcodeDecoderListener barcodeDecoderListener=new BarcodeDecoderListener()
{
public void barcodeDecoded(String rawText)
{
try
{
qrCodeScanner.beepSound();
barcodeScanner.stopScan();
qrCodeScanner.displayMessage(rawText);
}
catch (Exception e)
{
//Catch The Exception
}
}
};
try
{
barcodeScanner=new BarcodeScanner(barcodeDecoder, barcodeDecoderListener);
barcodeScanner.getVideoControl().setDisplayFullScreen(true);
add(barcodeScanner.getViewFinder());
}
catch (Exception e)
{
//Catch The Exception
}
}
public void startScan()
{
try
{
barcodeScanner.startScan();
}
catch (MediaException e)
{
//Catch The Exception
}
}
protected boolean keyChar(char key, int status, int time)
{
if (key == Characters.ESCAPE)
{
try
{
barcodeScanner.stopScan();
UiApplication.getUiApplication().popScreen(this);
}
catch (MediaException e)
{
QRCodeStartUp.errorHandling(e.getMessage());
}
}
return super.keyChar(key, status, time);
}
public void close()
{
try
{
barcodeScanner.stopScan();
}
catch (MediaException e)
{
//Catch The Exception
}
super.close();
}
protected boolean onSavePrompt()
{
return true;
}
}
any doubts feel free to mail on alishaik001@gmail.com
Only For Using Version >=6.0
-----------------------------------LoadingScreen.java-------------------------------------
public class LoadingScreen extends MainScreen implements FieldChangeListener
{
public BarCodeScannerScreen codeScannerView;
private LabelField showMessage;
private ButtonField scan;
private Font font;
private short _frequency = 1046;
private short _duration = 200;
private int _volume = 100;
public LoadingScreen()
{
setTitle("BAR CODE Demo");
font=Font.getDefault().derive(Font.BOLD|Font.ITALIC, 20);
createGUI();
}
private void createGUI()
{
LabelField label=new LabelField("Click The Button To Scan", Field.NON_FOCUSABLE|Field.FIELD_LEADING);
label.setFont(font);
label.setPadding(10, 0, 10, 0);
add(label);
scan=new ButtonField("Scan BARCODE", FIELD_HCENTER);
scan.setFont(font);
scan.setChangeListener(this);
add(scan);
showMessage=new LabelField();
showMessage.setFont(font);
showMessage.setPadding(10, 0, 0, 0);
add(showMessage);
}
public void fieldChanged(Field field, int context)
{
if(field==scan)
{
codeScannerView=new BarCodeScannerScreen(this);
UiApplication.getUiApplication().pushScreen(codeScannerView);
codeScannerView.startScan();
}
}
protected void beepSound()
{
UiApplication.getUiApplication().invokeLater(new Runnable()
{
public void run()
{
Alert.startAudio(new short[]{_frequency, _duration}, _volume);
}
});
}
public void displayMessage(String text)
{
synchronized (Application.getEventLock())
{
UiApplication.getUiApplication().popScreen(codeScannerView);
showMessage.setText(text);
}
}
protected boolean onSavePrompt()
{
return true;
}
}
-----------------------------------BarCodeScannerScreen .java-------------------------------------
public class BarCodeScannerScreen extends MainScreen
{
private LoadingScreen qrCodeScanner;
private BarcodeScanner barcodeScanner;
public BarCodeScannerScreen(LoadingScreen loadingScreen)
{
this.qrCodeScanner=loadingScreen;
Hashtable hashtable=new Hashtable();
Vector formats=new Vector(10);
formats.addElement(BarcodeFormat.QR_CODE);//In Blackberry These are the supported Formats
formats.addElement(BarcodeFormat.PDF_417);
formats.addElement(BarcodeFormat.CODE_128);
formats.addElement(BarcodeFormat.CODE_39);
formats.addElement(BarcodeFormat.DATA_MATRIX);
formats.addElement(BarcodeFormat.EAN_13);
formats.addElement(BarcodeFormat.EAN_8);
formats.addElement(BarcodeFormat.ITF);
formats.addElement(BarcodeFormat.UPC_A);
formats.addElement(BarcodeFormat.UPC_E);
hashtable.put(DecodeHintType.POSSIBLE_FORMATS, formats);
BarcodeDecoder barcodeDecoder=new BarcodeDecoder(hashtable);
BarcodeDecoderListener barcodeDecoderListener=new BarcodeDecoderListener()
{
public void barcodeDecoded(String rawText)
{
try
{
qrCodeScanner.beepSound();
barcodeScanner.stopScan();
qrCodeScanner.displayMessage(rawText);
}
catch (Exception e)
{
//Catch The Exception
}
}
};
try
{
barcodeScanner=new BarcodeScanner(barcodeDecoder, barcodeDecoderListener);
barcodeScanner.getVideoControl().setDisplayFullScreen(true);
add(barcodeScanner.getViewFinder());
}
catch (Exception e)
{
//Catch The Exception
}
}
public void startScan()
{
try
{
barcodeScanner.startScan();
}
catch (MediaException e)
{
//Catch The Exception
}
}
protected boolean keyChar(char key, int status, int time)
{
if (key == Characters.ESCAPE)
{
try
{
barcodeScanner.stopScan();
UiApplication.getUiApplication().popScreen(this);
}
catch (MediaException e)
{
QRCodeStartUp.errorHandling(e.getMessage());
}
}
return super.keyChar(key, status, time);
}
public void close()
{
try
{
barcodeScanner.stopScan();
}
catch (MediaException e)
{
//Catch The Exception
}
super.close();
}
protected boolean onSavePrompt()
{
return true;
}
}
any doubts feel free to mail on alishaik001@gmail.com
After scanning the qr code,it doesnt redirect me to the contained data..Can u help me to find out the problm?
ReplyDeleteIn this below method: "public void barcodeDecoded(String rawText)" did you check I am re-direct to my old screen by calling "displayMessage()" method('qrCodeScanner' which is the LoadingScreen variable). In this method I am popup the present screen.
ReplyDeleteThanks for your provide of the class to scans any type of the barcode image which is supports in Blackberry.
ReplyDeleteI tried to scan a qrcode out of the dec issue of game informer it was part of a tron game ad probably just a link to a online promo video. But I tried all the different scanning apps I could find as well as the bbm scanner nothing worked. I am beginning to think it is beyond the focus limitations of the camera. When the 83xx were developed QR codes did not really exists yet. Any way if anybody has been able to get any scanning app to work on 83xx please let me know would love to get it working.
In a word,i'm just new to this filed.Your blog is written very well, there is a lot of very useful knowledge to help me solve problems.I enjoy reading your blog and hope to see more.
This is a good resource for "Scan Any Type of Barcode Image"
ReplyDeleteIn additon to the listed barcode types, like QR Code, Data Matrix, Code 39, Code 128, is this barcode reading solution support Aztec Code?
See also: .NET barcode scanner sdk, QR Code scanner, Data Matrix scanner