我正在使用Xamarin.Android和ZXing.net.mobile C#库开发Android应用程序。
我想开发一款Android应用来扫描PDF-417中以base64字符串编码的二维条码。
这是我第一次使用这个库,但仍未找到有关如何使用该库的演示文档。
我已按照https://github.com/Redth/ZXing.Net.Mobile和here
中的示例进行操作以下是我的活动代码:
using Android.App;
using Android.Widget;
using Android.OS;
using ZXing;
using ZXing.Mobile;
using System;
using System.Collections.Generic;
namespace BarcodeScannerDemo
{
[Activity(Label = "ID Scanner Demo", MainLauncher = true)]
public class MainActivity : Activity
{
Button buttonScan;
MobileBarcodeScanner scanner;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
MobileBarcodeScanner.Initialize(Application);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
scanner = new MobileBarcodeScanner();
buttonScan = FindViewById<Button>(Resource.Id.buttonScan);
buttonScan.Click += ButtonScan_Click;
}
private async void ButtonScan_Click(object sender, EventArgs e)
{
var scannerOptions = new MobileBarcodeScanningOptions
{
PossibleFormats = new List<BarcodeFormat> { BarcodeFormat.PDF_417 },
TryHarder = true
};
var overlay = LayoutInflater.Inflate(Resource.Layout.CustomOverlay, null);
Button buttonFlash = overlay.FindViewById<Button>(Resource.Id.buttonFlash);
Button buttonCancel = overlay.FindViewById<Button>(Resource.Id.buttonCancel);
buttonCancel.Click += (btnCancelSender, btnCancelEventArgs) => scanner.Cancel();
buttonFlash.Click += (btnFlashSender, btnFlashEventArgs) => scanner.ToggleTorch();
scanner.UseCustomOverlay = true;
scanner.CustomOverlay = overlay;
scanner.AutoFocus();
HandleResult(await scanner.Scan(this, scannerOptions));
}
private void HandleResult(ZXing.Result result)
{
var message = "No Barcode!";
if (result != null)
{
message = $"{result.BarcodeFormat}";
}
Toast.MakeText(this, message, ToastLength.Long).Show();
}
}
}
应用程序在设备上编译和安装,我没有收到运行时错误,但是我没有得到扫描结果。扫描仪只是继续重新聚焦。我已将条形码格式限制为PDF-417。
我做错了什么?