Search code examples
androidzxing

ZXing IntentIntegrator always asks to install Barcode Scanner app


I am trying to use the ZXing Intent Integrator and Library to scan barcodes into my app. When I click the scan button, it will always prompt to install the Barcode Scanner app. Even when I already have it installed. Per the docmentation I call the scanner using

IntentIntegrator intentIntegrator = new IntentIntegrator(this);
intentIntegrator.initiateScan();

And then in

protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent intent) {
        super.onActivityResult(requestCode, resultCode, intent);
        IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
        if (scanResult != null) {
            String barcode = scanResult.getContents();
            EditText txt = findViewById(focused);
            txt.setText(barcode);
            EditText next = findViewById(focused + 1);
            next.requestFocus();
        }
}

However, the onActivityResult never gets called. Also in the IntentIntegrator class I found in the initiateScan method, it uses:

 String targetAppPackage = this.findTargetAppPackage(intentScan);
        if (targetAppPackage == null) {
            return this.showDownloadDialog();
        } else {
            intentScan.setPackage(targetAppPackage);
            intentScan.addFlags(67108864);
            intentScan.addFlags(524288);
            this.attachMoreExtras(intentScan);
            this.startActivityForResult(intentScan, 49374);
            return null;
        }

If I am reading this right, if the targetAppPackage is null, it prompts for the download. Well targetAppPackage is always returning null.

Any ideas? I've included the dependencies as required, but still nothing has worked.

Thanks!


Solution

  • After doing some more research I found here to add:

    repositories {
        mavenCentral()
    }
    
    dependencies {
        implementation 'com.journeyapps:zxing-android-embedded:4.2.0'
        implementation 'androidx.appcompat:appcompat:1.0.2'
    }
    
    android {
        buildToolsVersion '28.0.3' // Older versions may give compile errors
    }
    

    To the build.gradle file and <application android:hardwareAccelerated="true" ... > to the AndroidManifest.xml and it works great. No additional applications need to be installed, and no issues.