Skip to content

USER_CANCELLED or SCANNER_OPEN error not thrown #3

@onuh

Description

@onuh

(e) => {
let result = {
cancelled: false,
message: null,
};
switch (e) {
case null:
case 'USER_CANCELLED':
result.cancelled = true;
result.message = 'Scan was cancelled.';
break;
case 'SCANNER_OPEN':
result.message = 'Another scan is already in progress.';
break;
default:
result.message = e[0] || 'Unknown error.';
break;
}
onError(result);
},

BarcodeScanner.js made reference to error thrown when user cancels the scanner. The error is never thrown when user cancels the scanner. No error is also thrown using the back button to exit the scanner activity, this freezes the UI of my application. Though I was able to emit some error informing user that scanner was cancelled by editing the CaptureActivity.java file and updating:

_CloseButton.setOnClickListener(v -> {
finish();
})

to:

_CloseButton.setOnClickListener(v -> {
Intent data = new Intent();
//you can put intent.putExtra() here to define the error but I left blank so I can get "unknown error"
setResult(CommonStatusCodes.ERROR, data);
finish();
})

for the plugin to throw an "unknown error", I believe you can update the plugin with the appropriate string like "USER_CANCELLED" so we can check for this string in the JavaScript side in error.cancelled in the error function.

I also edited this block of code to make the back button emit an error which can be handled to inform user if the scanner is exited.

if ((results == null) || (results.size() == 0) || (results.get(0) == null)) {
DrawFocusRect(Color.parseColor("#FFFFFF"), null, null);
return;
}

to:

if ((results == null) || (results.size() == 0) || (results.get(0) == null)) {
DrawFocusRect(Color.parseColor("#FFFFFF"), null, null);
Intent data = new Intent();
//you can put intent.putExtra() here to define the error but I left blank so I can get "unknown error"
setResult(CommonStatusCodes.ERROR, data);
return;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions