Add more cancel case in scan return

This commit is contained in:
jacques 2022-03-11 10:14:28 +01:00
parent 273ae8bdfe
commit 15b7c52b66

View file

@ -296,6 +296,30 @@ public class DrugListActivity extends AppCompatActivity {
super.onResume();
}
/** Register the launcher and result handler
* ActivityResultLauncher
*/
private final ActivityResultLauncher<ScanOptions> barcodeLauncher = registerForActivityResult(new ScanContract(),
result -> {
if(result.getContents() == null) {
Intent originalIntent = result.getOriginalIntent();
if (originalIntent == null {
Log.d(TAG, "Cancelled Scan");
Toast.makeText(DrugListActivity.this, "Cancelled", Toast.LENGTH_LONG).show();
} else if (originalIntent.hasExtra(Intents.Scan.MISSING_CAMERA_PERMISSION)) {
Log.d(TAG, "Cancelled scan due missing camera permission");
Toast.makeText(DrugListaActivity.this, "Cancelled due missing camera persmission",
Toast.LENGTH_LONG.show());
} else if (originalIntent.hasExtra(Intents.Scan.TIMEOUT)) {
Log.d(TAG, "Cancelled due timeout");
Toast,makeText(DrugListActivity.this, "Cancelled due timeout", Toast.LENGTH_LONG.show());
}
} else {
Log.d(TAG, "Scanned");
Toast.makeText(DrugListActivity.this, "Scanned: " + result.getContents(),
Toast.LENGTH_LONG).show();
}
});
// Launch scan
public void onButtonClick() {
@ -306,7 +330,7 @@ public class DrugListActivity extends AppCompatActivity {
options.setCameraId(0); // Use a specific camera of the device
options.setBeepEnabled(true);
options.setBarcodeImageEnabled(true);
//options.setTimeout(3600);
options.setTimeout(60);
options.setCaptureActivity(CustomScannerActivity.class);
options.setBeepEnabled(true);
options.addExtra(Intents.Scan.SCAN_TYPE, Intents.Scan.MIXED_SCAN);