0

Since the ZXing.Net.Mobile has a problem on forms after 2.2.0 updates, I need to separate the ZXing into different platform. But the android version cannot work in PageRenderer.

Here is the info of my project:

Xamarin: 10.10

Android version: API 23

Project: Xamarin PCL Forms

ZXing version: 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);

                });

            }
 }

Update 2017-05-15

Screenshot of the QRCodeReader Screenshot of the QRCodeReader. It has empty view

Jacky Shek
  • 953
  • 1
  • 11
  • 35
  • What do you mean with "But the android version cannot work in PageRenderer" ? what error are you receiving? – pinedax May 15 '17 at 05:20
  • There is no error, but i will attach the screenshot of the mobile later. I hope that there is an errors, but no after checking logs. – Jacky Shek May 15 '17 at 06:16
  • @apineda There is no errors or any exceptions. The view returned empty. – Jacky Shek May 15 '17 at 06:29
  • Before looking into your implementation I wanna ask you what's the problem you found with Zxing and Forms using ZXingScannerPage? I am using this library with a Xamarin.Forms project 2.3.4.224, Zxing 2.2.9, Android Version 24 and I haven't seen any problem. – pinedax May 15 '17 at 06:33
  • @apineda The problem is that the ZXing of iOS version has bugs https://github.com/Redth/ZXing.Net.Mobile/issues/544 which cannot work perfectly. That makes me to build QRCode Scanner on each platform – Jacky Shek May 15 '17 at 07:25
  • @apineda I still cannot add the view, is a bug of the plugin or something wrong on my code? – Jacky Shek May 16 '17 at 10:01

0 Answers0