Android 在Xamarin表单应用程序中使用ZXing Mobile

Android 在Xamarin表单应用程序中使用ZXing Mobile,android,xamarin,xamarin.forms,zxing,Android,Xamarin,Xamarin.forms,Zxing,目前正在尝试使用ZXing Mobile为Xamarin表单构建应用程序 编译的代码没有问题。但在尝试在Android设备上运行时,我遇到了以下错误: An unhandled exception occcured. 日志显示以下内容: [0:] Binding: 'DefaultOverlayTopText' property not found on 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay', target property: 'ZXing.

目前正在尝试使用ZXing Mobile为Xamarin表单构建应用程序

编译的代码没有问题。但在尝试在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();

感谢您的帮助。谢谢。

我尝试了你的代码,发现错误与导航有关

您正在使用

await Navigation.PushAsync (scanPage);
确保从包含NavigationPage的页面调用此方法,否则将导致崩溃

要解决此问题,您可以使用

await Navigation.PushModalAsync (scanPage);
相反,它不需要NavigationPage,并且显示的结果页面将是模态的。使用上面的行,您还需要更改“弹出”视图的方式

await Navigation.PopModalAsync (true);
注意:

即使在工作时,这些消息也会出现在日志中

[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'

希望这有帮助。-

我尝试了你的代码,发现错误与导航更相关

您正在使用

await Navigation.PushAsync (scanPage);
确保从包含NavigationPage的页面调用此方法,否则将导致崩溃

要解决此问题,您可以使用

await Navigation.PushModalAsync (scanPage);
相反,它不需要NavigationPage,并且显示的结果页面将是模态的。使用上面的行,您还需要更改“弹出”视图的方式

await Navigation.PopModalAsync (true);
注意:

即使在工作时,这些消息也会出现在日志中

[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'

希望这能有所帮助。-

您使用的是什么版本的Zxing?Nuget还是组件?您是否也在请求摄像头的权限?版本为2.2.9。通过Nuget安装。是,权限添加到
AndroidManifest.xml
您使用的是哪个版本的Zxing?Nuget还是组件?您是否也在请求摄像头的权限?版本为2.2.9。通过Nuget安装。是,权限已添加到
AndroidManifest.xml
谢谢。不知道错误与缺少的
导航页面有关。不知道为什么错误消息没有暗示..谢谢。不知道错误与缺少的
导航页面有关。不知道为什么错误消息没有暗示。。