Xamarin ZXing初始化错误和缺少权限

Xamarin ZXing初始化错误和缺少权限,xamarin,zxing,Xamarin,Zxing,我有一个Xamarin.Forms项目,需要一个二维码扫描仪。我决定使用中兴图书馆。 安装工作正常,我在forms项目中创建了DependencyService接口,因此我可以在其中使用Android/iOS实现。我从这里得到了这方面的描述: 我的问题是没有一个构造函数只接受一个参数。只有一个参数为零 我有以下代码: [assembly: Dependency(typeof(QrCodeScanningService))] namespace my.project.Droid.Dependen

我有一个Xamarin.Forms项目,需要一个二维码扫描仪。我决定使用中兴图书馆。 安装工作正常,我在forms项目中创建了DependencyService接口,因此我可以在其中使用Android/iOS实现。我从这里得到了这方面的描述:

我的问题是没有一个构造函数只接受一个参数。只有一个参数为零

我有以下代码:

[assembly: Dependency(typeof(QrCodeScanningService))]
namespace my.project.Droid.DependencyServiceImplementations
{
    public class QrCodeScanningService : IQrCodeScanningService
    {
        public async Task<string> ScanAsync()
        {
            var scanner = new ZXing.Mobile.MobileBarcodeScanner(Application.Context); 
    // error: 'ZXing.Mobile.MobileBarcodeScanner' does not contain a constructor that takes 1 arguments

            var scanResults = await scanner.Scan();

            return scanResults.Text;
        }
    }
}
到目前为止,该库似乎在没有初始化和传递上下文的情况下工作,但我认为以这种方式使用它不是一个好主意

此外,当将应用程序置于后台并使其返回前台时,它会崩溃,但以下情况除外:

[MonoDroid] UNHANDLED EXCEPTION:
[MonoDroid] System.Exception: Couldn't get exclusive access to the camera
[MonoDroid] at ZXing.Mobile.ZXingSurfaceView.GetExclusiveAccess () <IL 0x00033, 0x00150>
[MonoDroid] at ZXing.Mobile.ZXingSurfaceView.StartScanning (ZXing.Mobile.MobileBarcodeScanningOptions,System.Action`1<ZXing.Result>) <IL 0x00046, 0x0028b>
[MonoDroid] at ZXing.Mobile.ZXingScannerFragment.scan () <IL 0x00012, 0x0007f>
[MonoDroid] at ZXing.Mobile.ZXingScannerFragment.OnResume () <IL 0x000fd, 0x00617>
[MonoDroid] at Android.Support.V4.App.Fragment.n_OnResume (intptr,intptr) <IL 0x0000a, 0x0009f>
[MonoDroid] at (wrapper dynamic-method) object.2ec0fbbb-3a10-48d4-b1ab-3fe72444ec91 (intptr,intptr) <IL 0x00011, 0x0003b>
[MonoDroid]未处理的异常:
[MonoDroid]系统。异常:无法以独占方式访问摄影机
[MonoDroid]位于ZXing.Mobile.ZXingSurfaceView.GetExclusiveAccess()
[MonoDroid]在ZXing.Mobile.ZXing surfaceview.StartScanning(ZXing.Mobile.MobileBarcodeScanningOptions,System.Action`1)
[MonoDroid]位于ZXing.Mobile.ZXingScannerFragment.scan()
[MonoDroid]位于ZXing.Mobile.ZXingScannerFragment.OnResume()
[MonoDroid]位于Android.Support.V4.App.Fragment.n_OnResume(intptr,intptr)
[MonoDroid]at(包装器动态方法)object.2ec0fbbb-3a10-48d4-b1ab-3fe72444ec91(intptr,intptr)
我不知道缺少初始化与此错误之间是否存在关系。相机权限已设置

有人能帮我纠正这些错误吗?
提前谢谢。

我只知道最近的版本中引入了不带上下文的初始化。这意味着他们没有更新文档,也没有更新最新版本来引入新的bug。顺便说一句,我使用的是1.4.7.1,非常感谢。你说1.4.7.1有效-你是说你在恢复应用程序时没有异常?这是他们引入的bug之一吗?是的,我在恢复应用程序时没有看到任何异常。但在某些设备中打开扫描仪视图时,会发生非常随机的崩溃。我之所以说“随机”,是因为这并不常见,而且我还没有发现如何重现这个错误。但是这个版本对于生产来说已经足够好了,我想我只知道在最近的版本中引入了没有上下文的初始化。这意味着他们没有更新文档,也没有更新最新版本来引入新的bug。顺便说一句,我使用的是1.4.7.1,非常感谢。你说1.4.7.1有效-你是说你在恢复应用程序时没有异常?这是他们引入的bug之一吗?是的,我在恢复应用程序时没有看到任何异常。但在某些设备中打开扫描仪视图时,会发生非常随机的崩溃。我之所以说“随机”,是因为这并不常见,而且我还没有发现如何重现这个错误。但我想那个版本已经足够适合生产了
[MonoDroid] UNHANDLED EXCEPTION:
[MonoDroid] System.Exception: Couldn't get exclusive access to the camera
[MonoDroid] at ZXing.Mobile.ZXingSurfaceView.GetExclusiveAccess () <IL 0x00033, 0x00150>
[MonoDroid] at ZXing.Mobile.ZXingSurfaceView.StartScanning (ZXing.Mobile.MobileBarcodeScanningOptions,System.Action`1<ZXing.Result>) <IL 0x00046, 0x0028b>
[MonoDroid] at ZXing.Mobile.ZXingScannerFragment.scan () <IL 0x00012, 0x0007f>
[MonoDroid] at ZXing.Mobile.ZXingScannerFragment.OnResume () <IL 0x000fd, 0x00617>
[MonoDroid] at Android.Support.V4.App.Fragment.n_OnResume (intptr,intptr) <IL 0x0000a, 0x0009f>
[MonoDroid] at (wrapper dynamic-method) object.2ec0fbbb-3a10-48d4-b1ab-3fe72444ec91 (intptr,intptr) <IL 0x00011, 0x0003b>