user11649010
user11649010

Reputation: 11

Ionic Native - Barcode Scanner does't work in production apk

I'm completing an app. the debug APK works correctly, while the signed version for publishing on the stores does not work properly, preventing me from inspecting the errors.

The problem is related to the Barcode-Scanner that I added to the project

$ ionic cordova plugin add phonegap-plugin-barcodescanner

$ npm install @ionic-native/barcode-scanner

I don't understand why the two apks behave differently.

I suppose it could be a permission issue but i didn't find enough documentation

Upvotes: 0

Views: 1089

Answers (3)

TigaPuluh Saat
TigaPuluh Saat

Reputation: 89

Permissions

<uses-permission android:name="android.permission.FLASHLIGHT" />
<uses-permission android:name="android.permission.CAMERA" />

I solve this issue by adding this permission at /platform/app/src/main/AndroidManifest.xml

recompile your apps and then it will ask user permissions for accessing camera.

Done.

Upvotes: 2

user11649010
user11649010

Reputation: 11

I "solved" the issue with this:

// import { BarcodeScanner } from '@ionic-native/barcode-scanner/ngx';

// private barcodeScanner: BarcodeScanner,

barcodeScanner = (<any>window).cordova.plugins.barcodeScanner;

Upvotes: 1

rtpHarry
rtpHarry

Reputation: 13125

Strange! I've been working with the same barcode scanner recently and in debug mode, it's worked fine.

When I changed the package name it reset everything back to defaults so I got asked for permission again.

This time as an experiment I denied it.

The app gave an error "Error: illegal access".

Do you have something to surface these kinds of issues?

This is what I have:

  async scanCode() {
    try {
      let barcodeData: BarcodeScanResult = await this.barcodeScanner.scan(this.barcodeScannerOptions);

      if (barcodeData.cancelled) {
        await this.msg.showAutoDismissToast("QR code scan cancelled");
        this.analytics.trackEvent("QR code scan cancelled");
        return;
      }

      this.addScannedDataToList(barcodeData);

      const scanResultModal = await this.modalController.create({
        component: ScanResultModalPage
      });

      await scanResultModal.present();

      await this.msg.showAutoDismissToast("QR code scanned");
    } catch (err) {
      await this.msg.showAutoDismissToast("Error: " + err);
    }
  }

You will need to tweak it a bit to your circumstance but it shows the basic idea of the try catch.

My showAutoDismissToast is nothing fancy, just a standard snippet:

  async showAutoDismissToast(message) {
    let toast = await this.toastController.create({
      message,
      duration: 2000,
      position: 'bottom'
    });

    await toast.present();
  }

Hopefully putting something like this in will surface the error that's preventing your scanner from working.

Upvotes: 0

Related Questions