Ionic Document Scanner: Incorrect result or user canceled the action

Viewed 573

I am having issue with the ionic document scanner (https://ionicframework.com/docs/native/document-scanner) which packaged the cordova-plugin-document-scanner (https://github.com/NeutrinosPlatform/cordova-plugin-document-scanner).

I am running this piece of code (copied from documentation)

ngAfterViewInit() {
    this.platform.ready().then((readySource) => {
        console.log('Platform ready from', readySource);
        // Platform now ready, execute any required native code
        let opts: DocumentScannerOptions = {};
        this.documentScanner.scanDoc(opts)
        .then((res: string) => console.log(res))
        .catch((error: any) => console.error(error));  
    });
}

The camera view is shown, I take the picture, the picture is shown for user validation. If I do accept the picture, this error is obtained:

Incorrect result or user canceled the action.

I cannot understand why this error is thrown. Versions:

Ionic CLI: 6.12.3

Ionic Framework: @ionic/angular 5.6.1

Cordova CLI: 10.0.0

Cordova Platforms: android 9.0.0

cordova-plugin-document-scanner 4.2.6 "Scan"

@ionic-native/document-scanner@5.31.1

Running on an android 11 device (OxygenOS 11.1.1)

Thank you for any help.

2 Answers

I fixed the problem disabling the backgroundMode plugin before taking the photo, then I enable the plugin again:

this.backgroundMode.disable();
   const OPTIONS: DocumentScannerOptions = {
       sourceType: 1,
       quality: 2.5,
       returnBase64; true
}
this.DocumentScanner.scanDoc (OPTIONS)
    .then ( result => {
          setTimeout ( () => {
              this.backgroundMode.enable();
          }, 500);
          console.log ( result );

Both camera and document scanner plugins have this conflict with backgroundMode plugin.

Related