0
votes

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

1
Your code looks ok. Use below code and post what it prints in catch block. this.barcodeScanner.scan().then(barcodeData => { console.log('Barcode data', barcodeData); }).catch(err => { console.log('Error', err); });Sudarshana Dayananda
thank you, I tried to add catch but nothing changed, I see that there is no problem in barcode scanner it self, it reads and fetch the barcode and after that in strange behavior it closes the current page and go to root page.Jafar Sabah

1 Answers

0
votes

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();
  });