Search code examples
ionic-frameworkionic3barcode-scanner

Ionic native barcodescanner not working in Android


I have ionic project scanning barcode, Im using @ionic-native/barcode-scanner it works fine on iOS, but in android when I call the scan method, the camera is opening and when it catch the barcode the apps crash and go to the root page (login). Im using LG Nexus android 6.0, can anyone help me please!

this.barcodeScanner.scan().then((data) => {
  this.addProduct(data.text);
}, (err) => {
  console.log(err);
});

Ionic:

ionic (Ionic CLI) : 4.0.1 (/usr/local/lib/node_modules/ionic)
Ionic Framework : ionic-angular 3.9.2 @ionic/app-scripts : 3.1.10

Cordova:

cordova (Cordova CLI) : 7.1.0 Cordova Platforms : android 7.1.1, browser 5.0.3, ios 4.5.5

System:

ios-deploy : 1.9.2 NodeJS : v6.10.0 (/usr/local/bin/node)
npm : 6.2.0 OS : macOS High Sierra Xcode : Xcode 9.4.1 Build version 9F2000


Solution

  • I have added onPauseSubscription in app.component so when I call the barcode scanner it calls this event automatically in android only. I removed it and it is working now.

    this.onPauseSubscription = platform.pause.subscribe(() => {
        console.log('onPauseSubscription'); // 30 sn
        this.logout();
      });