Search code examples
c#androidvisual-studioxamarinzxing

Lock screen orientation to portrait when scanning with Zxing library, Xamarin.android app.


I've seen it can be done in camera configuration manager but not sure where to find that file???

I've added:

          <activity android:name="MainActivity"

          android:configChanges="keyboardHidden|orientation" 

          android:screenOrientation="portrait"/>

And now the mainactivity is locked on portrait, but when running zxing scanner from inside activity the screen rotates during scan??


Solution

  • I have solved the issue, very simple in the end. I'm using Zxing.net.mobile, not zxing.net which is slightly different...

                var scanner = new MobileBarcodeScanner();
                scanner.TopText = "Scanning for Barcode...";
                var result = await scanner.Scan(new MobileBarcodeScanningOptions
                {
                    AutoRotate = false
                });
                if (result != null)
                {
                    _scan.ScanValue = result.ToString();
                    _scan.Action = "Scan";
                    await CallService();
                }
                else
                {
                    scanner.Cancel();
                    Recreate();
                }
            };
    

    This works well.