Developer’s Guide to Adding a .NET Barcode Scanner API

| Developers

Building or selecting an enterprise-grade .NET barcode scanner API for iOS and Android apps requires more than basic image capture and processing — UX principles and performance requirements are important too. With user adoption and longevity key goals for your app, the last things you want are user complaints because the scanner doesn’t perform under real-world business conditions.

This blog explains the UX and performance considerations that lead to successful barcode scanner implementations for enterprises. Later below, we provide a getting-started tutorial for adding scanning features to your applications using the Scandit SparkScan .NET Barcode Scanner SDK.

Why UX matters for .NET-based barcode scanning

Like staying within the memory and battery life limitations of all the devices you support, integrating a .NET barcode scanner library can be time-consuming and frustrating. Avoiding the risk of burdening users with performance issues and hard-to-use features ultimately leads to improved adoption rates and happier employees.

There are numerous UX considerations to consider, ranging from assistance features to ease of use. Knowing what to implement up front brings you happier users down the road.

A good barcode scanner needs more than a good camera

Good UX design creates a positive experience for users, leading to increased engagement and user satisfaction. For applications like barcode scanners, environmental conditions and varying levels of user skills can compromise the precision and accuracy necessary for effective captures. Proper navigation, interaction, and feedback help users do their jobs, and gaps in these areas lead quickly to frustration, dissatisfaction, and complaints.

Understanding the following UX workflows helps build the best barcode scanner experience for your user base.

Starting the scanner

Mobile device users have enough on their plates without worrying about complex menu navigation or waiting for a barcode scanner to start. Good UX requires a fast and seamless transition into scanning mode, no matter what the user is doing with their device.

The following video demonstrates how the Scandit SparkScan .NET Barcode Scanner SDK allows users to quickly access the scanner and work successfully in a wide variety of scanning environments.

Helping with aiming the camera

Aiming a camera can be difficult in environments where the barcode is hard to reach, or mixed in with other barcodes the user doesn’t want to scan. Building UX elements into your app that make selecting barcodes easier helps improve user efficiency and satisfaction.

Two examples of these types of elements are:

  • A viewfinder that tells users when scanning is active and helps them position the camera over the barcode correctly.
  • Restricting the scan area to help users focus on the correct barcode amidst a variety of barcodes and reduce the processing overhead on low-end devices.
PDF417 with DataMatrix with SparkScan

START BARCODE SCANNING WITH .NET

Add enterprise-class .NET barcode scanning in minutes with SparkScan

Feedback and assistance

Your .NET barcode scanner implementation should provide immediate and unambiguous feedback on the success or failure of a scan. A slow response leads to user frustration. Unclear results may also lead to inaccurate and potentially noncompliant data for the business.

A combination of techniques can be used to help the user scan successfully, such as:

  • Playing audio and triggering haptic feedback when a barcode capture is successful.
  • Drawing a brush overlay at the location of the detected barcode to confirm that the intended item was scanned by the app.

Providing options for single and multiple barcode scans

Features that allow the user to switch between scanning single and multiple barcodes help them work more efficiently. Environments where the number or configuration of barcodes varies, such as a warehouse or retail store, can slow down employees if they are forced to scan one barcode at a time.

SparkScan has two modes built into its .NET barcode scanner SDK:

  • Single scan: The user triggers the scanner for every barcode, providing greater control over the scanning experience.
  • Continuous scan: The user triggers the scanner once and the app scans multiple barcodes without further interaction, reducing user fatigue.

Which .NET barcode scanner API is best?

Here are some other considerations to think about when building your barcode scanner for iOS and Android applications.

1. Performance

Regardless of the device and version, you should consider the following performance requirements for your app and test cases:

  • Accuracy: Barcode scanning for high-volume operations, such as inventory management, asset tracking, and last-mile delivery, requires an implementation that accurately decodes barcodes with few or no errors. Even a 95% success rate is unlikely to be good enough – you should be looking for greater than 99% success.
  • Speed: A barcode scanner that helps users capture and process barcodes fast means accelerated business operations.
  • Scanning barcodes in degraded conditions: A barcode may be torn, obscured, crumpled, or wrapped in plastic, so your solution should account for all these scenarios.
  • Camera start-up time: To avoid frustrated users and slower operations, your barcode scanner should support a “standby state” that minimizes camera start-up delays between scans.
  • Capturing multiple barcodes fast: Users may need to scan multiple barcodes at once or in quick succession, such as a worker in a fulfillment center required to scan a product barcode and a location barcode fast to meet shipping times.
  • Field-of-view and distance: Scanners must handle barcodes on items of various sizes, shapes, and distances from the camera. The video below shows how SparkScan allows users to scan tiny electronic shelf labels (ESL) comfortably from far away without compromising speed or accuracy.

2. Low-light conditions

Lighting conditions in the real world vary widely between dark to brightly lit. Think about a back-of-store stockroom or a delivery driver working between day and night. Your .NET barcode scanner API should maintain speed and accuracy under all these conditions, otherwise, users will opt out of using it.

3. Large device fleets with diverse models

Enterprises often have a diverse fleet of employee devices with different camera specifications and processor architectures — especially in Bring-Your-Own-Device (BYOD) situations.

Your barcode scanner must be architected and designed to perform on iOS and Android platforms ranging from the latest smartphone model to legacy hardware. (You can see SparkScan’s system requirements here.)

We list key performance tests below to gauge how well your solution performs.

A solution should be highly optimized for processor performance and resource loading, and make efficient use of background tasks. The Scandit Data Capture SDK, for example, is built on a C/C++ foundation, ensuring that the core barcode scanning features are loaded efficiently in the background and consume minimal system resources.

4. Support for different development frameworks

For developers working in different environments, you may need to provide support for different platforms and frameworks. Scandit’s barcode scanning products are available for Native iOS, Native Android, Cordova, Xamarin and Xamarin.Forms, React Native, JavaScript, Flutter, Capacitor, and Titanium.

5. Open-source .NET barcode scanner libraries

Many .NET developers choose open-source barcode reader libraries for their ease of access and cost-effectiveness, thinking they only need basic features. The tradeoff comes when users try to use them in the real world, where speed and accuracy are critical, and where barcodes are placed in difficult-to-scan environments.

If you’re supporting a business-critical environment like a warehouse, retail stockroom, or last-mile delivery, an open-source .NET barcode reader library may not be the best choice. The overall performance of your app is only as strong as its slowest component, and open source tends not to perform as well as commercial libraries. Commercial barcode scanner SDKs that are high-performance, accurate, and built to operate under difficult situations are often better suited for demanding enterprise use cases.

Close up damaged label with SparkScan boxes on shelves

BARCODE SCANNING IN .NET MADE EASY

Integrate with just a few lines of code or use our samples

How do I create a barcode scanner in .NET?

SparkScan, part of the Scandit Smart Data Capture SDK, allows developers to add pre-built and intuitive barcode scanner capabilities to any iOS and Android application.

The SparkScan .NET barcode scanner API is built upon well-researched UX principles and optimized using feedback from thousands of Scandit customers across various environments. It provides a pre-built scanning interface that floats on top of any iOS and Android app. It reduces your development time and addresses common scanning pitfalls such as low light, torn labels, and long scanning distances.

You can customize the floating interface for different needs, such as providing audio or haptic feedback, allowing users to use the phone’s hardware button to trigger scans, and displaying a UI for left-handed users.

Graphic showing a React Native barcode scanner UI using the Scandit SparkScan pre-built barcode scanning component.

The next sections explain how to implement a customizable barcode scanning interface for iOS and Android in just a few steps with the Scandit .NET Barcode Scanner SDK.

Get started with SparkScan for .NET

Follow these SparkScan instructions to add pre-built barcode scanning features to your app:

.NET for iOS

Follow these steps to add barcode scanning and pre-built UI components using SparkScan to your iOS app. For additional help and examples of how to integrate barcode scanning:

The prerequisites for these steps are:

  • The latest stable version of Visual Studio.
  • A .NET SDK.
  • A .NET for iOS project with a minimum iOS deployment target of 13.0 or higher.
  • A valid Scandit Data Capture SDK license key. You can sign up for a free test account at ssl.scandit.com.

Although not covered here, the Scandit .NET Barcode Scanner SDK also supports scanning multiple barcodes at once (batch scanning). The instructions for setting up and using this capability are located in our Get Started With MatrixScan documentation.

1. Add the SDK

The Scandit Data Capture SDK is distributed as NuGet packages, which you get from the NuGet site.

You must add the Scandit.DataCapture.Core and Scandit.DataCapture.Barcode (the ScanditBarcodeCapture API) packages, which contain the functionality for barcode scanning. When developing a MAUI application, you also need to add the Scandit.DataCapture.Core.Maui package.

You must also consider:

  • Camera permissions: When using the Scandit Data Capture SDK, you must set the camera as the frame source for various capture modes. On .NET for iOS, you have to set the “Privacy – Camera Usage Description” field in the Info.plist file.
  • When using the Scandit Data Capture SDK in a MAUI application, you have to request camera permissions in your own application before starting scanning. To see how you can achieve this, take a look at our samples.

2. Create a new Data Capture Context instance

To add capture capabilities to your application, you must create a new data capture context, which expects a valid Scandit Data Capture SDK license key during construction:

DataCaptureContext context = DataCaptureContext.ForLicenseKey("-- ENTER YOUR SCANDIT LICENSE KEY HERE --");

3. Configure the SparkScan Mode

The SparkScan Mode is configured through SparkScanSettings, allowing you to register one or more listeners that are informed whenever a new barcode is scanned.

For this blog, we set up SparkScan for scanning EAN13 codes. Change this to the symbologies for your use case (for example, Code 128, Code 39).

SparkScanSettings settings = new SparkScanSettings();
HashSet<Symbology> symbologies = new HashSet<Symbology>()
{
    Symbology.Ean13Upca
};
settings.EnableSymbologies(symbologies);

Next, create a SparkScan instance with the settings initialized in the previous step:

SparkScan sparkScan = new SparkScan(settings);

4. Setup the SparkScan View

The SparkScan built-in user interface includes the camera preview and scanning UI elements. These guide the user through the scanning process.

The SparkScanView appearance can be customized through SparkScanViewSettings.

SparkScanViewSettings viewSettings = new SparkScanViewSettings();
// setup the desired appearance settings by updating the fields in the object above

Adding a SparkScanView automatically adds the scanning interface (camera preview and scanning UI elements) to your iOS application.

Next, add a SparkScan View to your view hierarchy by constructing a new SparkScan view. The SparkScan view is automatically added to the provided parentView:

SparkScanView sparkScanView = SparkScanView.Create(parentView, dataCaptureContext, sparkScan, viewSettings);

When developing on MAUI, the SparkScan view must be added as the last item to AbsoluteLayout or RelativeLayout, to make sure other UI components are visible:

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         xmlns:scandit="clr-namespace:Scandit.DataCapture.Barcode.Spark.UI.Unified;assembly=ScanditBarcodeCaptureUnified">
  <ContentPage.Content>
    <AbsoluteLayout>
      <!-- Your other UI components comes here before SparkScanView -->
      <scandit:SparkScanView
        x:Name="SparkScanView"
        AbsoluteLayout.LayoutBounds="0,0,1,1"
        AbsoluteLayout.LayoutFlags="All"
        DataCaptureContext="{Binding DataCaptureContext}"
        SparkScan="{Binding SparkScan}"
        SparkScanViewSettings="{Binding ViewSettings}">
      </scandit:SparkScanView>
    </AbsoluteLayout>
  </ContentPage.Content>
</ContentPage>

To ensure start-up time is optimal and that scanning is stopped when the app goes into the background, call SparkScanView.ViewWillAppear() and SparkScanView.ViewWillDisappear() in your UIViewController’s ViewWillAppear and ViewWillDisappear callbacks:

public override void ViewWillAppear(bool animated)
{
    base.ViewWillAppear(animated);
    sparkScanView.ViewWillAppear();
}

public override void ViewWillDisappear(bool animated)
{
    base.ViewWillDisappear(animated);
    sparkScanView.ViewWillDisappear();
}

To ensure optimal start-up time when developing on MAUI, make sure to call SparkScanView.OnAppearing and SparkScanView.OnDisappearing in your Page.OnAppearing and Page.OnDisappearing callbacks:

protected override void OnAppearing()
{
    base.OnAppearing();
    this.SparkScanView.OnAppearing();
}

protected override void OnDisappearing()
{
    base.OnDisappearing();
    this.SparkScanView.OnDisappearing();
}

5. Register the listener to be informed when a new barcode is scanned

To keep track of the scanned barcodes, implement the ISparkScanListener interface and register the listener to the SparkScan mode.

// Register self as a listener to monitor the SparkScan session.
sparkScan.addListener(this);

ISparkScanListener.OnBarcodeScanned() is called when a new barcode is scanned. This result is retrieved from the first object in the provided barcodes list: SparkScanSession.NewlyRecognizedBarcodes. Note that this list only contains one barcode entry.

public void OnBarcodeScanned(SparkScan sparkScan, SparkScanSession session, IFrameData? data)
{
    if (session.NewlyRecognizedBarcodes.Count == 0)
    {
        return;
    }

    // Gather the recognized barcode
    Barcode barcode = session.NewlyRecognizedBarcodes[0];

    // This method is invoked from a recognition internal thread.
    // Run the specified action in the UI thread to update the internal barcode list.
    DispatchQueue.MainQueue.DispatchAsync(() =>
    {
        // Update the internal list and the UI with the barcode retrieved above
        this.latestBarcode = barcode;
    });
}

Alternatively, to register ISparkScanListener interface, it is possible to subscribe to corresponding events. For example:

sparkScan.BarcodeScanned += (object sender, SparkScanEventArgs args) =>
{
    if (args.Session.NewlyRecognizedBarcodes.Count == 0)
    {
        return;
    }

    // Gather the recognized barcode
    Barcode barcode = args.Session.NewlyRecognizedBarcodes[0];

    // This method is invoked from a recognition internal thread.
    // Run the specified action in the UI thread to update the internal barcode list.
    DispatchQueue.MainQueue.DispatchAsync(() =>
    {
        // Update the internal list and the UI with the barcode retrieved above
        this.latestBarcode = barcode;
    });
}

.NET for Android

Follow these steps to add barcode scanning and pre-built UI components using SparkScan to your Android app. For additional help and examples of how to integrate barcode scanning:

The prerequisites for these steps are:

  • The latest stable version of Visual Studio.
  • A .NET SDK.
  • A .NET for Android project with target SDK version 23 (Android 6, Marshmallow) or higher.
  • A valid Scandit Data Capture SDK license key. You can sign up for a free test account at ssl.scandit.com.

1. Add the SDK

The Scandit Smart Data Capture SDK is distributed as NuGet packages, which you get from the NuGet site.

You must add the Scandit.DataCapture.Core and Scandit.DataCapture.Barcode (the ScanditBarcodeCapture API) packages, which contain the functionality for barcode scanning.

You must also consider:

  • The Scandit SDK uses content providers to initialize the scanning capabilities properly. If your own content providers depend on the Scandit SDK, choose an initOrder lower than 10 to make sure the SDK is ready first. If not specified, initOrder is zero by default and you have nothing to worry about. For more details, check the official Android documentation.
  • Camera permissions: When using the Scandit Smart Data Capture SDK, you must set the camera as the frame source for various capture modes. On .NET for Android or MAUI, you must request camera permissions in your application before starting scanning. To see how to do this, take a look at our samples.

2. Create a new Data Capture Context instance

To add capture capabilities to your application, you must create a new Data Capture Context, which expects a valid Scandit Data Capture SDK license key during construction:

DataCaptureContext dataCaptureContext = DataCaptureContext.ForLicenseKey("-- ENTER YOUR SCANDIT LICENSE KEY HERE --");

3. Configure the SparkScan Mode

The SparkScan Mode is configured through SparkScanSettings, allowing you to register one or more listeners that are informed whenever a new barcode is scanned.

For this blog, we set up SparkScan for scanning EAN13 codes. Change this to the symbologies for your use case (for example, QR Code, UPC Code).

SparkScanSettings settings = new SparkScanSettings();
HashSet<Symbology> symbologies = new HashSet<Symbology>()
{
    Symbology.Ean13Upca
};
settings.EnableSymbologies(symbologies);

Next, create a SparkScan instance with the settings initialized in the previous step:

SparkScan sparkScan = new SparkScan(settings);

4. Setup the SparkScan View

The SparkScan built-in user interface includes the camera preview and scanning UI elements. These guide the user through the scanning process.

The SparkScanView appearance can be customized through SparkScanViewSettings.

SparkScanViewSettings viewSettings = new SparkScanViewSettings();
// setup the desired appearance settings by updating the fields in the object above

Adding a SparkScanView automatically adds the scanning interface (camera preview and scanning UI elements) to your Android application.

Next, add a SparkScan View to your view hierarchy by constructing a new SparkScan view. The SparkScan view is automatically added to the provided parentView (preferably an instance of SparkScanCoordinatorLayout):

SparkScanView sparkScanView = SparkScanView.Create(parentView, dataCaptureContext, sparkScan, viewSettings);

When developing on MAUI, the SparkScan view must be added as the last item to AbsoluteLayout or RelativeLayout, to make sure other UI components are visible:

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         xmlns:scandit="clr-namespace:Scandit.DataCapture.Barcode.Spark.UI.Unified;assembly=ScanditBarcodeCaptureUnified">
  <ContentPage.Content>
    <AbsoluteLayout>
      <!-- Your other UI components comes here before SparkScanView -->
      <scandit:SparkScanView
        x:Name="SparkScanView"
        AbsoluteLayout.LayoutBounds="0,0,1,1"
        AbsoluteLayout.LayoutFlags="All"
        DataCaptureContext="{Binding DataCaptureContext}"
        SparkScan="{Binding SparkScan}"
        SparkScanViewSettings="{Binding ViewSettings}">
      </scandit:SparkScanView>
    </AbsoluteLayout>
  </ContentPage.Content>
</ContentPage>

Additionally for MAUI, to ensure optimal start-up time and that scanning is stopped when the app goes into the background, make sure to call SparkScanView.OnAppearing and SparkScanView.OnDisappearing in your Page.OnAppearing and Page.OnDisappearing callbacks:

protected override void OnAppearing()
{
    base.OnAppearing();
    this.SparkScanView.OnAppearing();
}

protected override void OnDisappearing()
{
    base.OnDisappearing();
    this.SparkScanView.OnDisappearing();
}

To ensure the correct functioning of the SparkScanView, call sparkScanView.onPause() and sparkScanView.onResume() in your Fragment/Activity onPause and onResume callbacks:

protected override void OnPause()
{
    sparkScanView.OnPause();
    base.OnPause();
}

protected override void OnResume()
{
    sparkScanView.OnResume();
    base.OnResume();
}

5. Register the listener to be informed when a new barcode is scanned

To keep track of the scanned barcodes, implement the ISparkScanListener interface and register the listener to the SparkScan mode.

// Register self as a listener to monitor the SparkScan session.
sparkScan.addListener(this);

ISparkScanListener.OnBarcodeScanned() is called when a new barcode is scanned. This result is retrieved from the first object in the provided barcodes list: SparkScanSession.NewlyRecognizedBarcodes. Note that this list only contains one barcode entry.

public void OnBarcodeScanned(SparkScan sparkScan, SparkScanSession session, IFrameData? data)
{
    if (session.NewlyRecognizedBarcodes.Count == 0)
    {
        return;
    }

    // Gather the recognized barcode
    Barcode barcode = session.NewlyRecognizedBarcodes[0];

    // This method is invoked from a recognition internal thread.
    // Run the specified action in the UI thread to update the internal barcode list.
    RunOnUiThread(() =>
    {
        // Update the internal list and the UI with the barcode retrieved above
        this.latestBarcode = barcode;
    });
}

Alternatively, to register ISparkScanListener interface, it is possible to subscribe to corresponding events. For example:

sparkScan.BarcodeScanned += (object sender, SparkScanEventArgs args) =>
{
    if (args.Session.NewlyRecognizedBarcodes.Count == 0)
    {
        return;
    }

    // Gather the recognized barcode
    Barcode barcode = args.Session.NewlyRecognizedBarcodes[0];

    // This method is invoked from a recognition internal thread.
    // Run the specified action in the UI thread to update the internal barcode list.
    RunOnUiThread(() =>
    {
        // Update the internal list and the UI with the barcode retrieved above
        this.latestBarcode = barcode;
    });
}

How to test .NET barcode scanning performance

The best way to test your .NET barcode scanner API for iOS or Android is to run it using real user scenarios. Whether you’re using your own solution or SparkScan, here are several performance-testing questions to ask:

  • Is there clear user guidance and feedback to foster smooth workflows rather than confuse scanning tasks?
  • Can you scan barcodes with reflections and glare?
  • Can you scan barcodes at a distance? Are you able to zoom in if needed?
  • Can you scan barcodes in different orientations, such as upside down and sideways? Flip the device upside down to see how the scanner performs.
  • Do you receive scanning feedback in loud environments and while wearing headphones?

You can also use our barcodes sample sheet for quick evaluation of your .NET barcode reader API.

Your .NET Barcode Scanner SDK is more than just a technical choice

Brilliant UX and performance are key development goals to ensure your .NET barcode scanner API works in the real world. Fewer user frustrations and adaptability to growing business demands are far preferable to low adoption rates and bug reports.

Next: Dive deeper into how to make a barcode scanning app performant →