Redth / ZXing.Net.Mobile

Barcode Scanner for Xamarin.iOS, Xamarin.Android, UWP and Tizen
MIT License
1.07k stars 703 forks source link

UWP: Check for camera #257

Open Templum opened 8 years ago

Templum commented 8 years ago

Using the latest version 2.0.4.46, I receive the following exception.

Message : "Object reference not set to an instance of an object." Source : "ZXingNetMobile" StackTrace : " at ZXing.Mobile.ZXingScannerControl.d13.MoveNext() --- End of stack trace from previous location where exception was thrown ---System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at ZXing.Mobile.ScanPage.d73.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<>c.b__6_0(Object state) at System.Threading.WinRTSynchronizationContext.Invoker.InvokeCore()"

I used the libary as shown in usages code and also tried the shown version in the uwp sample.

 public sealed partial class ShoppedPage : Page
    {
        MobileBarcodeScanner scanner;
        public ShoppedPage()
        {
            this.InitializeComponent();
            //Create a new instance of our scanner
            scanner = new MobileBarcodeScanner(this.Dispatcher);
            scanner.Dispatcher = this.Dispatcher;
        }

        private async void Scan_Click(object sender, RoutedEventArgs e)
        {

            //-- Config Scanner --//
            scanner.UseCustomOverlay = false;
            scanner.TopText = "Die Kamera auf den Barcode halten";
            scanner.BottomText = "Die Kamera sucht dan automatisch nach Barcodes \r\n\r\n 'Zurück' Tasten benutzen um Scannen abzubrechen";

            Result result = null;
            try
            {
                result = await scanner.Scan();
            }
            catch (Exception ex) { Debug.WriteLine(ex.Message); }

            String barcode = (String.IsNullOrEmpty(result?.Text)) ? "test" : result?.Text;
            Debug.WriteLine(barcode);
        }

    }
Redth commented 8 years ago

Have you declared the webcam device capability in your app manifest?

Templum commented 8 years ago

Actual this was the very first thing i did, but my test device had no camera connected. But this is something which should ne cause an exception right away

jasoncouture commented 7 years ago

@Redth Is there any way we can check for the camera in a XPlat way? My store app is getting rejected on windows 10 and xbox because the scanner page shows a white background because there is no camera.

I, obviously, can check on UWP, but it'd be much better for my use case if it were possible to check in the PCL project (Think cheap android tablets without a camera). My app doesn't require this feature to function.

(Since this seems to be related to this issue)