Android Question Converting Android "Studio" syntax to "B4A"

Discussion in 'Android Questions' started by Christopher Brown, Apr 4, 2015.


Would you like a Zbar library that can scan multiple barcode types, and static images?

  1. Yes

    3 vote(s)
  2. No

    0 vote(s)
  3. Not needed

    0 vote(s)
  1. Christopher Brown

    Christopher Brown Member Licensed User

    Bear with me via a brief intro ...

    I'm trying to scan QR codes. I installed "ABCameraTest" which in turn loads "BarCodeScanner" (ZXing?)
    But it has major drawbacks: The scanner will only work in landscape - even if activity set to portrait- it has a small viewfinder and needs a high contrast scan to work. (I understand the wording beneath can be changed with "intent.PutExtra" if such a command exists in B4A)

    So I'm looking at Zbar, which -from past experience of the Windows version - appears to be very tolerant to errors. I gave it some deliberately Gaussian blurred JPG's, angled at 45 degrees, and it managed to decode them. I gave it four images on a jpeg ... and it found all four barcodes.

    True, I'm now operating with an Android camera rather than images, but if it can cope with one ...

    This has been "ported" to Android ... but the syntax is based on Studio / Eclipse methodology, and obviously they do not match the variables that B4A uses.

    < LinearLayout xmlns:android=""

    < Button
    android:text="@string/scan_only_qr_codes" />

    < EditText
    android:ems="10" >

    < requestFocus />
    < /EditText>

    < /LinearLayout>

    This I can decode as simple buttons and TextEdit items, with the width set to full screen. However ...

    main Activity:
    private static final int ZBAR_QR_SCANNER_REQUEST = 1;

    onCreate() method:
    ((Button) findViewById(;

    public void launchQRScanner() {
    if (isCameraAvailable()) {
    Intent intent = new Intent(this, ZBarScannerActivity.class);
    new int[] { Symbol.QRCODE });
    startActivityForResult(intent, ZBAR_QR_SCANNER_REQUEST);
    } else {
    Toast.makeText(this, "Rear Facing Camera Unavailable", Toast.LENGTH_SHORT).show();
    public boolean isCameraAvailable() {
    PackageManager pm = getPackageManager();
    return pm.hasSystemFeature(PackageManager.FEATURE_CAMERA);

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {

    if (resultCode == RESULT_OK) {

    } else if (resultCode == RESULT_CANCELED && data != null) {
    String error = data.getStringExtra(ZBarConstants.ERROR_INFO);
    if (!TextUtils.isEmpty(error)) {

    Manifest (know where this goes - I think!)
    < uses-permission android:name="android.permission.CAMERA" />
    < uses-feature
    android:required="false" />
    < activity
    android:screenOrientation="landscape" />

    Can anyone help to 'decode' this into B4A parlance?
  2. DonManfred

    DonManfred Expert Licensed User

    USE CODE TAGs when posting code or manifest-code here!




    AND you dont need to create a POLL just to ask something... Just use the FIRST CREATE THREAD button. Not the second one at the bottom... This is just needed if you want to create a poll. Usually it is NOT needed
    lemonisdead and Peter Simpson like this.
  3. Christopher Brown

    Christopher Brown Member Licensed User

    Thanks for your advice on using the code option; I'll remember that for the next post.

    As for the poll, I thought I'd add that to see how many other people might be interested in a Zbar to B4A port. If enough people responded, my theory was that perhaps some programmers with more knowledge than me might take up the gantlet and convert the code.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice