diff --git a/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java b/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java index a19e48f..e2672cd 100644 --- a/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java @@ -296,6 +296,30 @@ public class DrugListActivity extends AppCompatActivity { super.onResume(); } + /** Register the launcher and result handler + * ActivityResultLauncher + */ + private final ActivityResultLauncher 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);