[Codename One] QR code scanner with Zxing

926 views
Skip to first unread message

Roy lee

unread,
Mar 13, 2013, 10:11:37 PM3/13/13
to codenameone...@googlegroups.com

I'm developing a mobile app(android & ios), which enables user to scan QR code, using Zxing.

At this moment, I've tried out the QR scanner demo provided in codenameone_docs_demos_20130307.zip, which works in Ipad.


Questions:

  1. Is it possible to configure the scan area, to be smaller? (The default demo is difficult for me to scan SMALL QR code, the default scanning area is too big)

  2. Is there a way to configure the scanner UI? E.g: a line or point, to facilitate user to focus.

Shai Almog

unread,
Mar 14, 2013, 2:26:16 AM3/14/13
to codenameone...@googlegroups.com
Not really, we use zbar which has support for barcodes (unlike zxing on iOS) but doesn't have a QR code implementation of the same level. To circumvent that you can incorporate code from the ZXing demo for the iOS portion only and you might get a better QR code scanning experience. Regardless this is native code so customizing it requires going into native.

Roy lee

unread,
Mar 14, 2013, 2:35:36 AM3/14/13
to codenameone...@googlegroups.com
Thanks for the reply :) Does that means I have to maintain 2 codebases, each IOS and android? Can it be done with just one codebase?

Apart from that, is there tutorial available to achieve this? (write native code on codenameone?)

P/S: Bear with me as I'm fairly new to mobile development. :)

Shai Almog

unread,
Mar 14, 2013, 2:39:41 AM3/14/13
to codenameone...@googlegroups.com
One code base is fine. Check out the native interfaces in the zxing demo. There is a check to see if native is supported... You can just return false for Android and then fallback to use the code scanner package as the default.
So effectively you will only copy the native implementation of the iOS version.

Roy lee

unread,
Mar 14, 2013, 2:46:19 AM3/14/13
to codenameone...@googlegroups.com
code scanner package? How do I obtain this?

This is what I've saw in Zxing Demo:
  1. Zxing.Java
  2. ZXingNativeCalls.Java
I still can't get what needed to be done..Can you guide me in this?

Shai Almog

unread,
Mar 14, 2013, 2:52:40 PM3/14/13
to codenameone...@googlegroups.com
I assumed you saw the scan demo. Check out the kitchen sink demo under the camera section there is a button to capture QR codes using com.codename1.codescan.CodeScanner.

        if(CodeScanner.getInstance() != null) {
           
final Button qrCode = new Button("Scan QR");
            cnt
.addComponent(qrCode);
            qrCode
.addActionListener(new ActionListener() {
               
public void actionPerformed(ActionEvent evt) {
                   
CodeScanner.getInstance().scanQRCode(new ScanResult() {
                       
public void scanCompleted(String contents, String formatName, byte[] rawBytes) {
                            qrCode
.setText("QR: " + contents);
                       
}

                       
public void scanCanceled() {
                       
}

                       
public void scanError(int errorCode, String message) {
                       
}
                   
});
               
}
           
});
           
final Button barCode = new Button("Scan Barcode");
            cnt
.addComponent(barCode);
            barCode
.addActionListener(new ActionListener() {
               
public void actionPerformed(ActionEvent evt) {
                   
CodeScanner.getInstance().scanBarCode(new ScanResult() {
                       
public void scanCompleted(String contents, String formatName, byte[] rawBytes) {
                            barCode
.setText("Bar: " + contents);
                       
}

                       
public void scanCanceled() {
                       
}

                       
public void scanError(int errorCode, String message) {
                       
}
                   
});
               
}
           
});
       
}


Reply all
Reply to author
Forward
0 new messages