当前正试图使用ZXing Mobile为Xamarin Forms构建应用程序。在Xamarin Forms应用程序中使用ZXing Mobile
编译的代码没有问题。但是,试图将Android设备上运行的时候,我得到了以下错误:
An unhandled exception occcured.
日志显示以下内容:
[0:] Binding: 'DefaultOverlayTopText' property not found on 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay', target property: 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay.TopText'
[0:] Binding: 'DefaultOverlayBottomText' property not found on 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay', target property: 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay.BottomText'
[0:] Binding: 'DefaultOverlayShowFlashButton' property not found on 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay', target property: 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay.ShowFlashButton'
[0:] Binding: 'DefaultOverlayTopText' property not found on 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay', target property: 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay.TopText'
[0:] Binding: 'DefaultOverlayBottomText' property not found on 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay', target property: 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay.BottomText'
[0:] Binding: 'DefaultOverlayShowFlashButton' property not found on 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay', target property: 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay.ShowFlashButton'
我这是怎么实现的:
scanButton.Clicked += async (sender, args) =>
{
var options = new MobileBarcodeScanningOptions
{
AutoRotate = false,
UseFrontCameraIfAvailable = false,
TryHarder = true
};
var scanPage = new ZXingScannerPage(options)
{
DefaultOverlayTopText = "Align the barcode within the frame",
DefaultOverlayBottomText = string.Empty,
DefaultOverlayShowFlashButton = true
};
// Navigate to our scanner page
await Navigation.PushAsync(scanPage);
scanPage.OnScanResult += (result) =>
{
// Stop scanning
scanPage.IsScanning = false;
// Pop the page and show the result
Device.BeginInvokeOnMainThread(async() =>
{
await Navigation.PopAsync();
await DisplayAlert("Scanned Barcode", result.Text, "OK");
});
};
};
还增加以下是Android的主要活动,位于Xamarin自己的Init上方:
ZXing.Net.Mobile.Forms.Android.Platform.Init();
任何帮助表示赞赏。谢谢。
什么版本的斑马线您使用的是? Nuget或组件?你是否也要求获得相机的许可? – apineda
该版本是2.2.9。通过Nuget安装。是的,权限被添加到'AndroidManifest.xml'上。 – ipohfly