How To

How to add barcode scanning to a .NET MAUI app

A five-step guide to barcode scanning in a .NET MAUI app with the barKoder SDK: install the NuGet package, allow the camera, add the scanner view, choose the barcode types and read the results.

Tutorial cover: Build a Barcode Scanner App with .NET MAUI and barKoder SDK
On this page

Five steps take a .NET MAUI app from nothing to live barcode scanning with the barKoder SDK: install a NuGet package, grant camera access, drop in a view, configure it, and read results.

Barcode scanning is one of those features that sounds like a weekend project and then eats a week. The barKoder plugin wraps a native scanner engine behind a single MAUI control, so you get camera handling, decoding, and result delivery without writing platform-specific code.

By the end of this guide you'll have a page that scans QR and Code 128 barcodes and prints each result to the console. You'll need an existing .NET MAUI project and, optionally, a barKoder license key.

What you'll need

  • A .NET MAUI project targeting Android and/or iOS
  • The Plugin.Maui.Barkoder NuGet package
  • A barKoder license key (optional while testing; see Step 4)

Step 1: Add the package and register the handler

Start by adding the Plugin.Maui.Barkoder NuGet package to your project. Then tell MAUI how to render the scanner view by registering BarkoderViewHandler in MauiProgram.cs.

First, import the controls namespace:

using Plugin.Maui.Barkoder.Controls;

Then add the handler inside ConfigureMauiHandlers:

var builder = MauiApp.CreateBuilder();
builder
    .UseMauiApp<App>()
    .ConfigureFonts(fonts =>
    {
        // Your custom fonts
    })
    .ConfigureMauiHandlers(handlers =>
    {
        // Your other MAUI handlers
        handlers.AddHandler(typeof(BarkoderView), typeof(BarkoderViewHandler));
    });

Without this registration the app stops at startup with a HandlerNotFoundException.

Step 2: Allow camera access

The scanner can't run without camera permission, and each platform asks for it differently.

Platform

What to do

Android

Nothing extra. The permission is already declared in the package's manifest.

iOS

Add a camera usage description to Platforms/iOS/Info.plist.

For iOS, add this entry and replace the text with a short explanation your users will see in the permission prompt:

<key>NSCameraUsageDescription</key>
<string>Camera permission</string>

A specific message such as "Used to scan product barcodes" tells users why the app needs the camera, and Apple may reject apps with vague wording.

Step 3: Add the scanner view

Declare the plugin namespace in your XAML page so you can use its controls:

xmlns:barkoder="clr-namespace:Plugin.Maui.Barkoder.Controls;assembly=Plugin.Maui.Barkoder"

Then place a BarkoderView where you want the camera preview. Replace YOUR_LICENSE_KEY with the key from your barKoder account:

<barkoder:BarkoderView
    x:Name="BKDView"
    barkoder:LicenseKey="YOUR_LICENSE_KEY"
    HeightRequest="200"/>

In the matching code-behind file (.xaml.cs), import the types you'll use later:

using Plugin.Maui.Barkoder.Handlers;
using Plugin.Maui.Barkoder.Interfaces;
using Barkoder;

The x:Name is what lets your C# code talk to the scanner, so keep it and use the same name everywhere.

Step 4: Configure settings and barcode types

The scanner works with defaults, but you'll usually want to choose which barcode formats to read. Add a settings method to your code-behind and call it once when the page is ready:

using Plugin.Maui.Barkoder.Enums;

...

private void SetBarkoderSettings()
{
    // Optional settings; defaults apply if you skip these
    BKDView.SetImageResultEnabled(true);
    BKDView.SetLocationInImageResultEnabled(true);
    BKDView.SetRegionOfInterestVisible(true);

    // Enable the barcode types you need
    BKDView.SetBarcodeTypeEnabled(BarcodeType.QR, true);
    BKDView.SetBarcodeTypeEnabled(BarcodeType.Code128, true);
}

The three optional settings do the following:

  • SetImageResultEnabled returns the captured image along with the decoded result.
  • SetLocationInImageResultEnabled returns where in the image the barcode was found.
  • SetRegionOfInterestVisible draws the scan area on screen so users know where to aim.

Enabling only the formats you expect is a good habit, since fewer active types means less work for the decoder.

A note on licensing
The SDK scans without a license, but every result comes back with an "(Unlicensed)" prefix and part of its data replaced with dots. To remove it, create a barKoder account and get either a trial license for testing or a production license for a live app. By using the software you agree to barKoder's End User License Agreement.

Step 5: Start scanning and read results

Results arrive through a callback. Make your page implement IBarkoderDelegate, call StartScanning on the view, and handle codes in DidFinishScanning:

public partial class YourPage : ContentPage, IBarkoderDelegate
{
    // Your existing methods and properties...

    // Starts the scanning process
    private void StartScanning()
    {
        // Pass 'this' as the delegate so results come back to this page
        BKDView.StartScanning(this);
    }

    // Called by the SDK when barcodes are decoded
    public void DidFinishScanning(BarcodeResult[] result, ImageSource[] thumbnails, ImageSource originalImageSource)
    {
        foreach (var barcode in result)
        {
            Console.WriteLine($"Scanned barcode: {barcode.TextualData}");
        }
    }
}

Each BarcodeResult exposes the decoded text through TextualData. Swap the Console.WriteLine for whatever your app needs, such as looking up a product, filling a form field, or navigating to a detail page.

You now have the full loop: package installed, handler registered, camera allowed, view on the page, formats configured, and results flowing into your code.

If something doesn't work, check these first:

  • Is BarkoderViewHandler registered in MauiProgram.cs?
  • Does Info.plist contain NSCameraUsageDescription on iOS?
  • Did you call SetBarkoderSettings() before StartScanning(this)?
  • Do results start with "(Unlicensed)"? That means the license key is missing or invalid.

You can find all the details and more examples in the .NET MAUI documentation.