I'm trying to write an app with an integrated barcode scanner. I followed this tutorial: https://www.c-sharpcorner.com/article/xamarin-android-qr-code-reader-by-mobile-camera/
The scan works fine and very fast (before I used ZXing.Net.Mobile and it is horrible slow). Now I need some help to integrate that the app only detects one barcode when the user presses a button and not the whole time. Maybe a delay would solve the problem too.
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.ScannerTest);
surfaceView = FindViewById<SurfaceView>(Resource.Id.cameraView);
txtResult = FindViewById<TextView>(Resource.Id.txtResult);
barcodeDetector = new BarcodeDetector.Builder(this)
.SetBarcodeFormats(BarcodeFormat.Code128 | BarcodeFormat.Ean13 | BarcodeFormat.QrCode)
.Build();
cameraSource = new CameraSource
.Builder(this, barcodeDetector)
.SetRequestedPreviewSize(320, 480)
.SetAutoFocusEnabled(true)
.Build();
surfaceView.Click += StartScanning;
surfaceView.Holder.AddCallback(this);
//barcodeDetector.SetProcessor(this);
}
private void StartScanning(object sender, EventArgs e)
{
barcodeDetector.SetProcessor(this);
}
public void ReceiveDetections(Detections detections)
{
SparseArray qrcodes = detections.DetectedItems;
if (qrcodes.Size() != 0)
{
txtResult.Post(() => {
//Vibrator vibrator = (Vibrator)GetSystemService(Context.VibratorService);
//vibrator.Vibrate(1000);
txtResult.Text = ((Barcode)qrcodes.ValueAt(0)).RawValue;
});
}
}
At the moment the user presses the SurfaceView and the scanner starts and never stops.
Is it possible, that it just scans one after pressing the "button"?
r3d007