0

由于ZXing.Net.Mobile2.2.0 更新后表单出现问题,我需要将其分离ZXing到不同的平台。但是安卓版本无法运行PageRenderer

这是我的项目的信息:

Xamarin:10.10

安卓版本:API 23

项目:Xamarin PCL 表单

ZXing版本:2.1.47

App.Android - AndroidManifest:

 <manifest ...../>
        <uses-permission android:name="android.permission.CAMERA" />
          <uses-permission android:name="android.permission.FLASHLIGHT" />
          <uses-feature android:name="android.hardware.camera" />
          <uses-feature android:name="android.hardware.camera.autofocus" />
          <uses-feature android:name="android.hardware.camera.flash" />
    <application ....

App.Android - MainActivity.cs :

protected override void OnCreate(Bundle bundle)
{
           base.OnCreate(bundle);
           MobileBarcodeScanner.Initialize(Application);

}

App.Android - QRCodePageRenderer:

class QRCodePageRenderer : PageRenderer
{
        private ZXingScannerFragment ScanFragment;
        ZXingSurfaceView ZxingScanningView;
        private Android.Views.View ZxingOverlay;
        FrameLayout frame;
        public bool ContinuousScanning { get; set; }
        protected override void OnElementChanged(ElementChangedEventArgs<Page> e)
        {
            base.OnElementChanged(e);

            var activity = this.Context as Activity;
            LayoutInflater layoutInflater = (LayoutInflater)this.Context.GetSystemService(Context.LayoutInflaterService);
            frame = (FrameLayout)layoutInflater.Inflate(Resource.Layout.zxingscannerfragmentlayout, null);
            ZxingScanningView = new ZXingSurfaceView(activity);
            ScanningOptions = new MobileBarcodeScanningOptions();
            ScanningOptions.PossibleFormats = Constants.QRCODE_SCAN_FORMAT;


            try
            {
                var scanner = new ZXingSurfaceView(activity, ScanningOptions);
                var layoutParams = getChildLayoutParams();
                frame.AddView(scanner, layoutParams);
                ZxingOverlay = new ZxingOverlayView(activity);
                frame.AddView(ZxingOverlay, layoutParams);
                this.AddView(frame);

            }
            catch (Exception ex)
            {
                Console.WriteLine("Create Surface View Failed: " + ex);
            }

            ScanFragment = new ZXingScannerFragment();
            ScanFragment.TopText = "ABC";
                Task.Factory.StartNew(() =>
                {
                    Console.WriteLine("StartNew scan .....");

                    ScanFragment.StartScanning(result => {

                        if (!ContinuousScanning)
                        {
                            Console.WriteLine(result.Text);
                            Console.WriteLine("Stopping scan...");

                            ScanFragment.PauseAnalysis();

                        }
                    }, this.ScanningOptions);

                });

            }
 }

2017-05-15 更新

QRCodeReader 的屏幕截图 QRCodeReader 的屏幕截图。 它有空视图

4

0 回答 0