I'm using BlackBerry Java Plugin 1.3 Eclipse.
And Simulator of 9300.
You can download the package classes here.
Example of Usage:
BarcodeScanner scanner;
BarcodeDecoder decoder;
BarcodeDecoderListener listener;
Field viewFinder;
BarcodeDecoder decoder;
BarcodeDecoderListener listener;
Field viewFinder;
Hashtable hints = new Hashtable(1);
Vector formats = new Vector(1);
formats.addElement(BarcodeFormat.QR_CODE);
hints.put(DecodeHintType.POSSIBLE_FORMATS, formats);
decoder = new BarcodeDecoder(hints);
listener = new BarcodeDecoderListener() {
public void barcodeFailDecoded(Exception ex) {
}
public void barcodeDecoded(String rawText) {
synchronized(Application.getEventLock()){
barcodeResult.setText(rawText);
}
}
public void barcodeDecodeProcessFinish() {
synchronized(Application.getEventLock()){
UiApplication.getUiApplication.
popScreen(ViewFinderScreen.this);
}
}
};
try {
scanner = new BarcodeScanner(decoder, listener);
viewFinder = scanner.getViewFinder();
scanner.getVideoControl.setDisplayFullScreen(true);
add(viewFinder);
scanner.startScan();
} catch (Exception e) {
Status.show(e.getMessage());
e.printStackTrace();
}
Vector formats = new Vector(1);
formats.addElement(BarcodeFormat.QR_CODE);
hints.put(DecodeHintType.POSSIBLE_FORMATS, formats);
decoder = new BarcodeDecoder(hints);
listener = new BarcodeDecoderListener() {
public void barcodeFailDecoded(Exception ex) {
}
public void barcodeDecoded(String rawText) {
synchronized(Application.getEventLock()){
barcodeResult.setText(rawText);
}
}
public void barcodeDecodeProcessFinish() {
synchronized(Application.getEventLock()){
UiApplication.getUiApplication.
popScreen(ViewFinderScreen.this);
}
}
};
try {
scanner = new BarcodeScanner(decoder, listener);
viewFinder = scanner.getViewFinder();
scanner.getVideoControl.setDisplayFullScreen(true);
add(viewFinder);
scanner.startScan();
} catch (Exception e) {
Status.show(e.getMessage());
e.printStackTrace();
}
To stop scan
try {
scanner.stopScan();
} catch (MediaException e) {
e.printStackTrace();
}
Dowload sample usages here
QR Code Sample
thanks for the good work!
ReplyDeleteUsingBarcodeLib works wonderfully on OS5 simulator, but on OS6 simulators it shows the QR code and does nothing.. any idea?
Great work! Seems to work on OS5 and OS6 devices.
ReplyDeleteI will write if I found any bugs!
Thanks for sharing these. could build on api 4.5 and tested ok on 4.5+ simulators and 6 device.
ReplyDeleteNice post! Did you try to generate QR code ?
ReplyDeleteI am using Blackberry 9700, OS 6, and Java SDK 5 on Eclipse 3.6.2.
ReplyDeleteThis code doesn't scan QR-code below a certain size (compared to scanner in Java SDK 6) and takes longer to detect the code. I can visually see that there is something wrong with focus.
This is very interesting to try. I want to try to make my first blackberry.
ReplyDeleteIn OS 6, there is already a Barcode scanner library, and already added google ZXing library.
ReplyDeletePlease check on net.rim.device.api.barcodelib
I'm having difficulties on testing the library on 8520. Have you tested on 8520? because from what i've experienced, since lack of auto focus, I can't capture the barcode using 8520 camera. any idea?
ReplyDeleteThere are several way to capture barcode.
ReplyDeleteThere is some tutorial show how to capture using camera, to capture image on screen.
This one is using camera when user click.
Some other way is using ViewFinder which can invoke camera to capture image and show on ViewFinder (which is field and can be put on screen)
Try to use different delay, such as 3, 4 seconds then capturing screen using
Bitmap bmpScreenshot = new Bitmap(Display.getWidth(),Display.getHeight());
Display.screenshot(bmpScreenshot);
Hi,
ReplyDeleteHow to encode a string to bitmap on Blackberry 5.0?
Mostly here is code convert from array of bytes to bitmap
ReplyDeleteEncodedImage image = EncodedImage.createEncodedImage(imageData, 0, imageData.length);
Bitmap bmp = image.getBitmap();
If you have string representation of image, I think you should convert it to array of bytes. using getBytes() method. Hope it helps
Great work...!
ReplyDeleteI use this for all 5.0 below versions of os, it's working and scanning qrcodes but takes long time to scan and can't capture images below certain dimensions, can you please increase the speed of scanning...
wen..gimana cara embed ke aplikasi yang menggunakan JRE 6. saya pake directive #ifdef (supaya bs digunakan di versi mana aja)
ReplyDelete//#ifdef OS_6_0
if(_viewFinderScreen == null) {
_viewFinderScreen = new ViewFinderScreen();
}
UiApplication.getUiApplication().pushScreen(_viewFinderScreen);
_viewFinderScreen.startScan();
//#else
pake lib barcode utk v5.0
//
#endif
tolong email apa saja code2 dan lib yg dibutuhkan ke bagussujarwo@ymail.com
thanks
hey , and if I want to open the cam to detect if there's a barcode to be scanned can you give me an example :)
ReplyDelete@BagusSujarwo
ReplyDelete(Indonesian)
Untuk di OS 6.0
Aku sarankan menggunakan library dari RIM yang sudah disediakan di OS 6.0
Contoh di atas adalah workaround untuk di OS 5.0, dikarenakan secara default tidak ada
Cek di dokumentasi package BarcodeLib
net.rim.device.api.barcodelib
@Rucha
ReplyDeletefor increase speed of scanning
maybe you can modify the code change the interval
http://www.4shared.com/zip/lNUj0cCJ/BBBarcodeLib.html
Get the code here, and please modify. Thanks.
@Zenkology,
ReplyDeletecould you describe what you are going to do?
@omgimanoob
ReplyDeleteon OS6, please use RIM library on
net.rim.device.api.barcodelib
@Ali irwan actually um going to add a scan for qr code in my app so i need to open camera after I press a button (sry for being late in reply ) :)
ReplyDelete@Zenkology
ReplyDeleteOkay, you can use ViewFinder, please see my code on blackberry barcode lib that I'd share.
Just modify, and use the ViewFinder. The ViewFinder itself, shows what camera capture and display it on screen as a Field. ViewFinder is subclass of Field
You will need class VideoPlayer which will have method getSnapshot()
trigger the method when button is pushed. I've found this example somewhere in RIM Knowlegde base.
try hit a question on www.stackoverflow.com instead
ureHey, thanks a lot. Works great on 5.0 devices
ReplyDeletehey thanks, works great on 5.0 devices
ReplyDeleteHi, Its not working on BB OS 7.0 device, please help me out.
ReplyDeleteRegards,
Naveen
@Naveen
ReplyDeleteif you using BB OS 7.0
please don't use this code, untested.
Please use default BlackbBerry library for barcode scanning. (Barcodelib is available built in since 6.0)
Check this link
First of all, thanks for sharing this!
ReplyDeleteThis lib worked just fine with 9300 and 8520 but it doesn't with 9700. I modified the code to show me the bitmap it's getting in the screenshot and 9700's picture is always a blank screen...any idea what would it be?
hey man i am facing problem with default qr code reader lib for OS 6.0 with device model no 9800. Code opens camera but does not read qr code neither it gives any exception pls help me
ReplyDeleteNot works in BB Storm with OS 5.0 neither in BB Curve 9300 with OS 5.0.
ReplyDeleteIn my BB 9360 with OS 7.0 works great, can scan EAN-13, UPC-A, QR.
Why no works in OS 5.0 ??
This comment has been removed by the author.
ReplyDeleteif anyone cannot generate bar-code there is the solution:
ReplyDeleteprivate void generate(BarcodeFormat format, int width, int height) {
Hashtable hints = new Hashtable();
// Assuming UTF-8 since text is passed via JSON.
hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
MultiFormatWriter writer = new MultiFormatWriter();
BitMatrix result = null;
try {
result = writer.encode(text.getText(), format, width, height,
hints);
} catch (WriterException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
width = result.getWidth();
height = result.getHeight();
// Create a new bitmap which will be filled pixel by pixel from the
// generated BitMatrix.
Bitmap bitmap = new Bitmap(width, height);
// An integer array to hold a row of bitmap pixels at a time.
int[] pixels = new int[width];
// Loop through the generated BitMatrix and fill the Bitmap.
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
// Pixel needs to be black (0xFF000000) or white
// (0xFFFFFFFF)
pixels[x] = result.get(x, y) ? 0xFF000000 : 0xFFFFFFFF;
}
bitmap.setARGB(pixels, 0, width, 0, y, width, 1);
}
_barcodeField.setBitmap(bitmap);
}
where width bitmapfield width,and height bitmapfield height
thx very much for ali irawan for this fantastic post :D
ReplyDeleteThanks for adding the code
ReplyDeleteHey...Veryyy good work!!!....Thanks for the sample app. The ZXling has demo application for blackberry QR code reader but that is not proper & not decoding image.
ReplyDeleteBut by using & understanding ur code we can make changes in ZXling demo project so that it cud work....
Thankssssss....a lottttttt :-)
Sure nice to help :)
ReplyDeleteDo we need to buy the package in http://www.4shared.com/file/lNUj0cCJ/BBBarcodeLib.html to download the code?
ReplyDeletehttp://www.4shared.com/file/lNUj0cCJ/BBBarcodeLib.html - where the code is available for scanning QA code for version less than 6.0 is not free.
ReplyDeleteDid you guys pay for it to get the cource?
No need. It's totally free.
ReplyDeletePlease download and review the code.
You can modify for your need
Hi,
ReplyDeletePlease provide me any example for QR code which run into device because right now i am not download your sample code.
Thanks.
Here is it:
ReplyDeletehttp://www.multiupload.nl/Y2M547TI3A
Please tell me if u don't understand anything :)
it works on 8520, 9360 but it didn't work on 9550. any clue?
ReplyDeleteHow you turn on the debugger? To find out what error message occurs ?
ReplyDeleteMOre clear information is better to troubleshoot.
hmmm, after i debug. Display.screenshot results blankscreen or usingbarcodescreen.
ReplyDeletehttp://supportforums.blackberry.com/t5/Java-Development/Display-screenshot-problem-capturing-camera-view-on-9780-9650/td-p/1623943
ReplyDeletei think the only solution is by using videocontroller.getsnapshot() instead
Your package classes are very important and useful.
ReplyDeleteThanks Wen.
Okay, thanks.
ReplyDeleteIt's nice to help people.
Any suggesstion for more topic via email to boylevantz@gmail.com
Hi All,
ReplyDeleteI take a MissingNativeError
using your source as a Library.
Somebody can help me?
I creata a library using Eclipse and I import it on my project.
thank you in advance
I prefer you copy the source code an embedded in your app.
ReplyDeleteBut If you do want to create library make sure when you create a project in Eclipse, choose blackberry library project.
It will be set in application Descriptor whether it's library or application
thanks, for this workaround
ReplyDeleteHello, 4shared.com https login seems to be not working at the moment, and I really need this, can you send me it to mrabooode@gmail.com
ReplyDeleteWhen we use this code through menu in a webview screen, invokelater method is not execute.
ReplyDeleteThanks for your recommendation of the barcode scanner SDK and the example of usage is wonderful.
ReplyDeleteI enjoy reading your article and hope to see more.
This comment has been removed by the author.
ReplyDelete