8
votes

I am developing a universal app for both Windows 8.1 and Windows Phone 8.1 which I want to be able to scan barcodes. For Windows 8.1, there exists a native class BarcodeScanner which is unfortunately inaccessible for Windows Phone 8.1 (I really don't understand what led Microsoft to do it this way). I found a 3rd party solution called zxing, but here I have read that it works terribly for universal apps. What is the best way to implement barcode scanning functionality in universal apps?

Thank you!

1
Until Microsoft finally merges WP and WinRT (supposedly in Win10), there will be disparities in the API.BitBank
Use a Bluetooth scanner.Matt Small
Don't create a Universal app. Build the apps separately and share as much code as possible via class libraries or some other means.pumpkinszwan
windows phone also has a barcode scanner built in - as you can use this directly from the phone search button - at least for scanning QR codes - so it stands to reason that this may be exposed as an api call somewhere.morishuz
You may want to look into BrokeredPointOfService, which is sort of a bridge between POS for .NET and WinRT - could be an alternative to using the Windows.Devices.PointOfService API methods. Although I am not familiar enough with it to know if it works with Windows Phone or not.Daniel A. Thompson

1 Answers

1
votes

I would just use a text box. Most barcode scanners will act as keyboards and after a scan will send an enter key input. If your text box listens to the key up event and checks for the enter key you will know when a scan is complete. I personally would not use the Point of service. It's from an old version of .NET and from my experience it won't even work on desktop apps. This is what it would look like for me.

private void TextBox1_KeyUp(object sender, KeyEventArgs e)
    {
        if (e.Key == Key.Enter)
        {
            this.MyFunction(this.TextBox1.Text);
        }
    }

The nice thing about doing it this way is that the program can run without the barcode scanner if needed. The user can just type in the number and hit enter. The downside is that the text box needs to be selected in order for the program to receive input. In order to reduce or eliminate the user having to select the textbox all the time you can set the focus using this.TextBox1.Focus().