0

So i followed googles tutorial for their barcode scanner (this one) and the qr scanning works like a charm. The only problem is that i don't need qr codes but rather bar codes. But they don't work. It doesn't detect anything. I tried multiple online bar codes and ones from around the house but none got recognised as a barcode.

this is the code in my activity that handles the image and scanner:

public void btnClick(View v) {

    Intent imageTakeIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

    if(imageTakeIntent.resolveActivity(getPackageManager())!=null){
        startActivityForResult(imageTakeIntent, 101);
    }
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if(requestCode==101 && resultCode==RESULT_OK) {
        Bundle extras = data.getExtras();
        Bitmap imageBitmap = (Bitmap) extras.get("data");
        imageView.setImageBitmap(imageBitmap);
        image = InputImage.fromBitmap(imageBitmap, 0);
        barCodeScanning();
    }
}

public void barCodeScanning(){
    BarcodeScannerOptions options =
            new BarcodeScannerOptions.Builder()
                    .setBarcodeFormats(
                            Barcode.FORMAT_CODE_128,
                            Barcode.FORMAT_CODE_93,
                            Barcode.FORMAT_CODE_93,
                            Barcode.FORMAT_CODABAR,
                            Barcode.FORMAT_EAN_13,
                            Barcode.FORMAT_EAN_8,
                            Barcode.FORMAT_ITF,
                            Barcode.FORMAT_UPC_A,
                            Barcode.FORMAT_UPC_E,
                            Barcode.FORMAT_PDF417,
                            Barcode.FORMAT_DATA_MATRIX,
                            Barcode.FORMAT_QR_CODE,
                            Barcode.FORMAT_AZTEC)
                    .build();
    BarcodeScanner scanner = BarcodeScanning.getClient();
    Task<List<Barcode>> result = scanner.process(image)
            .addOnSuccessListener(new OnSuccessListener<List<Barcode>>() {
                @Override
                public void onSuccess(List<Barcode> barcodes) {
                    System.out.println(barcodes.size());
                    for (Barcode barcode: barcodes) {
                        Rect bounds = barcode.getBoundingBox();
                        Point[] corners = barcode.getCornerPoints();

                        String rawValue = barcode.getRawValue();
                        System.out.println(rawValue);

                        int valueType = barcode.getValueType();
                        System.out.println(valueType);
                    }
                }
            })
            .addOnFailureListener(new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    e.printStackTrace();
                }
            });
}

The console looks fine to me except the line E/libc: Access denied finding property "ro.hardware.chipname" which is marked red but didn't turn up any helpful results on google. This is the complete console output:

02/26 18:29:10: Launching 'app' on HMD Global Nokia 5.3.
Install successfully finished in 2 s 230 ms.
$ adb shell am start -n "com.project.kuecheninventar/com.project.kuecheninventar.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Connected to process 28314 on device 'hmd_global-nokia_5_3-N0AA003687KA2700363'.
Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
I/Perf: Connecting to perf service.
W/kuecheninventa: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
I/AdrenoGLES: QUALCOMM build                   : cfd6c90, Id60e6598a1
Build Date                       : 01/27/20
OpenGL ES Shader Compiler Version: EV031.27.05.03
Local Branch                     : mybranchea40f85b-21cb-f1fb-b0c0-5cb90179c3e0
Remote Branch                    : quic/gfx-adreno.lnx.1.0.r91-rel
Remote Branch                    : NONE
Reconstruct Branch               : NOTHING
Build Config                     : S P 8.0.12 AArch64
I/AdrenoGLES: PFP: 0x016ee187, ME: 0x00000000
W/Gralloc3: mapper 3.x is not supported
D/TransportRuntime.JobInfoScheduler: Scheduling upload for context TransportContext(cct, VERY_LOW, MSRodHRwczovL2ZpcmViYXNlbG9nZ2luZy5nb29nbGVhcGlzLmNvbS92MGNjL2xvZy9iYXRjaD9mb3JtYXQ9anNvbl9wcm90bzNc) with jobId=-1883559869 in 86400000ms(Backend next call timestamp 0). Attempt 1
I/DynamiteModule: Considering local module com.google.mlkit.dynamite.barcode:10000 and remote module com.google.mlkit.dynamite.barcode:0
Selected local version of com.google.mlkit.dynamite.barcode
I/tflite: Initialized TensorFlow Lite runtime.
I/native: barcode_detector_client.cc:239 Not using NNAPI
E/libc: Access denied finding property "ro.hardware.chipname"
D/TransportRuntime.SQLiteEventStore: Storing event with priority=VERY_LOW, name=FIREBASE_ML_SDK for destination cct
D/TransportRuntime.JobInfoScheduler: Upload for context TransportContext(cct, VERY_LOW, MSRodHRwczovL2ZpcmViYXNlbG9nZ2luZy5nb29nbGVhcGlzLmNvbS92MGNjL2xvZy9iYXRjaD9mb3JtYXQ9anNvbl9wcm90bzNc) is already scheduled. Returning...
I/System.out: 0
D/TransportRuntime.SQLiteEventStore: Storing event with priority=VERY_LOW, name=FIREBASE_ML_SDK for destination cct
D/TransportRuntime.JobInfoScheduler: Upload for context TransportContext(cct, VERY_LOW, MSRodHRwczovL2ZpcmViYXNlbG9nZ2luZy5nb29nbGVhcGlzLmNvbS92MGNjL2xvZy9iYXRjaD9mb3JtYXQ9anNvbl9wcm90bzNc) is already scheduled. Returning...
D/TransportRuntime.SQLiteEventStore: Storing event with priority=VERY_LOW, name=FIREBASE_ML_SDK for destination cct
D/TransportRuntime.JobInfoScheduler: Upload for context TransportContext(cct, VERY_LOW, MSRodHRwczovL2ZpcmViYXNlbG9nZ2luZy5nb29nbGVhcGlzLmNvbS92MGNjL2xvZy9iYXRjaD9mb3JtYXQ9anNvbl9wcm90bzNc) is already scheduled. Returning...
D/TransportRuntime.SQLiteEventStore: Storing event with priority=VERY_LOW, name=FIREBASE_ML_SDK for destination cct
D/TransportRuntime.JobInfoScheduler: Upload for context TransportContext(cct, VERY_LOW, MSRodHRwczovL2ZpcmViYXNlbG9nZ2luZy5nb29nbGVhcGlzLmNvbS92MGNjL2xvZy9iYXRjaD9mb3JtYXQ9anNvbl9wcm90bzNc) is already scheduled. Returning...

The line System.out.println(barcodes.size()); just prints 0 which means the barcode list is empty. Did i do something wrong or why does the qr code regognize but no bar code?

mr.jogurt
  • 43
  • 8
  • Mysterious :) In order to help you better, could you provide: 1. which version / variant (bundled/unbundled) of the Barcode scanning API are you using 2. examples of one or two of the 1D barcodes "E/libc: Access denied finding property "ro.hardware.chipname" is a red herring, not related to this issue. It's basically a check for HW accelerator that is failing. You could also see if you can reproduce with our official quickstart app: https://github.com/googlesamples/mlkit/tree/master/android/vision-quickstart – Chrisito Feb 26 '21 at 18:15
  • @Chrisito im using the bundled version. Here are 2 barcodes i tested: https://imgur.com/a/eN9hvuj could you tell me how to compile the github version? I get the error 'Error: The apk for your currently selected variant (Unknown output) is not signed. Please specify a signing configuration for this variant (proguard).' in the Run/Debug Configuration window in AndroidStudio. – mr.jogurt Feb 27 '21 at 16:08
  • 1
    Thanks. Let me get some help from more knowledgable folks, please stay tuned. – Chrisito Mar 02 '21 at 04:07
  • Hi, those barcodes can be detected using the mlkit quickstart app. If you want to recognize barcode from a local image, could you check the mlkit quickstart app code here: https://github.com/googlesamples/mlkit/blob/369dd896f4b7fadeedd3e0860f2e1695db0b4d9b/android/vision-quickstart/app/src/main/java/com/google/mlkit/vision/demo/java/StillImageActivity.java#L297 for reading a bitmap from url and feed it to the barcode scanner api? There might be an issue with the InputImage. – Chenxi Song Mar 02 '21 at 22:52
  • BTW, to build the mlkit vision quickstart app you can change the build variant if you use Android Studio: select Build > Select Build Variant in the menu bar. Check more details in the answers here: https://github.com/googlesamples/mlkit/issues/123 – Chenxi Song Mar 02 '21 at 23:15
  • @mr.jogurt any update, I hope you got 1D bar code scanning working in the end? – Chrisito Mar 19 '21 at 18:23
  • @Chrisito thanks for both your help. I added another solution (via zxing) as an answer. I used this solution because the deadline on the university project was coming up. – mr.jogurt Mar 29 '21 at 15:06

1 Answers1

-2

I forgot about this issue because i solved through another way. So here is my solution with zxing: In the app built.gradle use implementation 'com.journeyapps:zxing-android-embedded:4.1.0'

public class BarCodeScanner extends AppCompatActivity {

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        scan();
    }

    private void scan() {
        IntentIntegrator i = new IntentIntegrator(this);

        i.setDesiredBarcodeFormats(IntentIntegrator.PRODUCT_CODE_TYPES);

        i.setCaptureActivity(CaptureActivitaet.class);
        i.setOrientationLocked(false);
        i.setBeepEnabled(false);
        i.setPrompt("Scanning");
        i.initiateScan();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        IntentResult res = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
        if (res != null) {
            if (res.getContents() != null) {
                AlertDialog.Builder builder = new AlertDialog.Builder(this);
                builder.setMessage(res.getContents());
                builder.setTitle(getString(R.string.scanComplete));
                builder.setPositiveButton(R.string.ok, (dialogInterface, i) -> {
                    setResult(RESULT_OK, new Intent().putExtra("code", res.getContents()));
                    finish();
                }).setNegativeButton(R.string.scanAgain, (dialogInterface, i) -> scan());
                AlertDialog dialog = builder.create();
                dialog.show();
            } else {
                Toast.makeText(this, "No Results", Toast.LENGTH_LONG).show();
            }
        } else {
            super.onActivityResult(requestCode, resultCode, data);
        }
    }
}

The capture activity is just an empty activity public class CaptureActivitaet extends CaptureActivity {} although it has to be configured in the Manifest file like this:

    <activity
        android:name="com.project.Grocerly.UI.CaptureActivitaet"
        android:screenOrientation="fullSensor"
        android:stateNotNeeded="true"
        android:windowSoftInputMode="stateAlwaysHidden" />

This opens a fullscreen camera activity which scans codes accordingly to the types set via i.setDesiredBarcodeFormats(IntentIntegrator.PRODUCT_CODE_TYPES); in the scan() methode. The extra capture activity can probably be skipped if you use setCaptureActivity(this.class) and configure it correctly in the manifest file but im not sure about that.

Because this was a project for university this code isn't very pretty but it works and that was my main concern at the time.

mr.jogurt
  • 43
  • 8
  • 1
    ZXing is in maintenance mode only and shouldn't be used anymore. I have the same issue as in the question -this is not the answer but a workaround. – seeppp May 20 '21 at 07:58