IRONSOFTWAREHOME

How to Read and Write Barcode on Android in .NET MAUI

Curtis Chau
Curtis Chau
Updated: August 2, 2026

.NET MAUI (Multi-platform App UI) is the successor to Xamarin.Forms, enabling developers to build cross-platform applications for Android, iOS, macOS, and Windows using .NET. It streamlines the development process by allowing the creation of native user interfaces that work seamlessly across multiple platforms.

The BarCode.Android package brings barcode support to Android!

IronBarcode Android Package

The BarCode.Android package enables barcode features on Android devices via .NET cross-platform projects. The vanilla BarCode package is not needed.

PM > Install-Package BarCode.Android

C# NuGet Library for PDF

Install with NuGet

Install-Package BarCode.Android

Create a .NET MAUI Project

Open Visual Studio and click on "Create a new project". Search for MAUI, select .NET MAUI App and "Next".

Include the BarCode.Android Library

The library can be added in various ways. The easiest is perhaps by using NuGet.

  1. Inside Visual Studio, right-click on "Dependencies" and select "Manage NuGet Packages ...".
  2. Select the "Browse" tab and search for "BarCode.Android".
  3. Select the "BarCode.Android" package and click on "Install".

To prevent issues with other platforms, modify the csproj file to only include the package when targeting the Android platform. In order to do so:

  1. Right-click on the *.csproj file for your project and select "Edit Project File".

  2. Create a new ItemGroup element as such:

    <ItemGroup Condition="$(TargetFramework.Contains('android')) == true">
        <PackageReference Include="BarCode.Android" Version="2025.3.4" />
    </ItemGroup>
    XML
  3. Move the "BarCode.Android" PackageReference inside the ItemGroup we just created.

The above steps will prevent the "BarCode.Android" package from being used on platforms such as iOS. For that purpose, install BarCode.iOS instead.

Configure the Android Bundle

For Android to work, you need to configure the Android bundle settings. In your ".csproj" file, add the following entry to specify the configuration file for the Android bundle:

<AndroidBundleConfigurationFile>BundleConfig.json</AndroidBundleConfigurationFile>
XML

Create a file named "BundleConfig.json" in the root directory of the project. This JSON file contains the required settings for the Android bundle, which are crucial for the library's functionality.

{
    "optimizations": {
        "uncompress_native_libraries": {}
    }
}
JSON

This configuration ensures that native libraries are uncompressed, which is a necessary step for the library to function properly in the Android environment.

Design the App Interface

Update the XAML file to allow users to input values for generating barcodes and QR codes. Additionally, add a button to choose a document for barcode reading. Here's an example:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="IronBarcodeMauiAndroid.MainPage">

    <VerticalStackLayout Padding="20">
        <HorizontalStackLayout>
            <CheckBox x:Name="generatePdfCheckBox" IsChecked="{Binding IsGeneratePdfChecked}" />
            <Label Text="PDF (unchecked for PNG)" VerticalOptions="Center"/>
        </HorizontalStackLayout>
        
        <Entry x:Name="barcodeInput" Placeholder="Enter barcode value..." />
        <Button Text="Generate and save barcode" Clicked="WriteBarcode" />

        <Entry x:Name="qrInput" Placeholder="Enter QR code value..." />
        <Button Text="Generate and save QR code" Clicked="WriteQRcode" />

        <Button
            Text="Read Barcode"
            Clicked="ReadBarcode"
            Grid.Row="0"
            HorizontalOptions="Center"
            Margin="20, 20, 20, 10"/>
        <ScrollView
            Grid.Row="1"
            BackgroundColor="LightGray"
            Padding="10"
            Margin="10, 10, 10, 30">
            <Label x:Name="OutputText"/>
        </ScrollView>
    </VerticalStackLayout>

</ContentPage>
XML

Read and Write Barcodes

From the MainPage.xaml code above, we can see that the checkbox determines whether the generated barcode and QR code should be in PDF format. Next, we set the license key. Please use either a trial or paid license key for this step.

The code checks and retrieves the value from the barcodeInput variable, then uses the CreateBarcode method to generate the barcode. Finally, it calls the SaveToDownloadsAsync method, which saves the file appropriately for both Android and iOS.

On iOS, a custom file path is required to export the document to the Files application.

using IronBarCode;
using System;
using System.IO;
using System.Threading.Tasks;
using Xamarin.Essentials;

namespace IronBarcodeMauiAndroid
{
    public partial class MainPage : ContentPage
    {
        public bool IsGeneratePdfChecked
        {
            get => generatePdfCheckBox.IsChecked;
            set
            {
                generatePdfCheckBox.IsChecked = value;
            }
        }

        public MainPage()
        {
            InitializeComponent();
            // Set the license key for IronBarcode, replace with your actual license key.
            License.LicenseKey = "IRONBARCODE-MYLICENSE-KEY-1EF01";
        }

        private async void WriteBarcode(object sender, EventArgs e)
        {
            try
            {
                if (!string.IsNullOrEmpty(barcodeInput.Text))
                {
                    // Create a barcode from the text input with the EAN13 encoding.
                    var barcode = BarcodeWriter.CreateBarcode(barcodeInput.Text, BarcodeEncoding.EAN13);

                    // Determine the file extension and data format based on the checkbox state.
                    string fileExtension = IsGeneratePdfChecked ? "pdf" : "png";
                    string fileName = $"Barcode_{DateTime.Now:yyyyMMddHHmmss}.{fileExtension}";
                    byte[] fileData = IsGeneratePdfChecked ? barcode.ToPdfBinaryData() : barcode.ToPngBinaryData();

                    // Save the generated barcode to the Downloads folder.
                    await SaveToDownloadsAsync(fileData, fileName);

                    await Application.Current.MainPage.DisplayAlert("Saved", "File saved to Downloads folder", "OK");
                }
            }
            catch (Exception ex)
            {
                // Handle exceptions and log the error.
                System.Diagnostics.Debug.WriteLine(ex);
            }
        }

        private async void WriteQRcode(object sender, EventArgs e)
        {
            try
            {
                if (!string.IsNullOrEmpty(qrInput.Text))
                {
                    // Create a QR code from the text input.
                    var barcode = QRCodeWriter.CreateQrCode(qrInput.Text);

                    // Determine the file extension and data format based on the checkbox state.
                    string fileExtension = IsGeneratePdfChecked ? "pdf" : "png";
                    string fileName = $"QRcode_{DateTime.Now:yyyyMMddHHmmss}.{fileExtension}";
                    byte[] fileData = IsGeneratePdfChecked ? barcode.ToPdfBinaryData() : barcode.ToPngBinaryData();

                    // Save the generated QR code to the Downloads folder.
                    await SaveToDownloadsAsync(fileData, fileName);

                    await Application.Current.MainPage.DisplayAlert("Saved", "File saved to Downloads folder", "OK");
                }
            }
            catch (Exception ex)
            {
                // Handle exceptions and log the error.
                System.Diagnostics.Debug.WriteLine(ex);
            }
        }

        private async void ReadBarcode(object sender, EventArgs e)
        {
            try
            {
                var options = new PickOptions
                {
                    PickerTitle = "Please select a file"
                };
                var file = await FilePicker.PickAsync(options);

                OutputText.Text = "";

                if (file != null)
                {
                    using var stream = await file.OpenReadAsync();

                    BarcodeResults result;

                    if (file.ContentType.Contains("image"))
                    {
                        // Read barcodes from an image file.
                        result = BarcodeReader.Read(stream);
                    }
                    else
                    {
                        // Read barcodes from a PDF file.
                        result = BarcodeReader.ReadPdf(stream);
                    }

                    string barcodeResult = "";
                    int count = 1;

                    // Retrieve and format the barcode reading results.
                    result.ForEach(x => { barcodeResult += $"Barcode {count}: {x.Value}\n"; count++; });

                    OutputText.Text = barcodeResult;
                }
            }
            catch (Exception ex)
            {
                // Handle exceptions and log the error.
                System.Diagnostics.Debug.WriteLine(ex);
            }
        }

        public async Task SaveToDownloadsAsync(byte[] fileData, string fileName)
        {
            var downloadsPath = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDownloads);
            var filePath = Path.Combine(downloadsPath.AbsolutePath, fileName);

            try
            {
                // Create the directory if it doesn't exist.
                if (!Directory.Exists(downloadsPath.AbsolutePath))
                {
                    Directory.CreateDirectory(downloadsPath.AbsolutePath);
                }

                // Save the file to the Downloads folder.
                await File.WriteAllBytesAsync(filePath, fileData);
            }
            catch (Exception ex)
            {
                // Log errors if file saving fails.
                System.Diagnostics.Debug.WriteLine("Error saving file: " + ex.Message);
            }
        }
    }
}

Run the Project

This will show you how to run the project and use the barcode feature.

Execute .NET MAUI App project

Download .NET MAUI App Project

You can download the complete code for this guide. It comes as a zipped file that you can open in Visual Studio as a .NET MAUI App project.

Click here to download the project.

Frequently Asked Questions

What is .NET MAUI and how does it relate to barcode scanning on Android?

.NET MAUI, or Multi-platform App UI, is the successor to Xamarin.Forms, allowing developers to build cross-platform applications. The BarCode.Android package integrates with .NET MAUI to enable barcode reading and writing on Android devices.

How do I add the BarCode.Android library to my .NET MAUI project?

You can add the BarCode.Android library using NuGet in Visual Studio. Right-click on 'Dependencies', choose 'Manage NuGet Packages', search for 'BarCode.Android', and click 'Install'.

Can the BarCode.Android package be used for platforms other than Android?

The BarCode.Android package is specifically tailored for Android. For iOS, you need to use the BarCode.iOS package instead.

How can I configure my project to include the BarCode.Android library only for Android?

You should edit your .csproj file to include a conditional ItemGroup for the BarCode.Android package only when targeting Android, using the TargetFramework condition.

Do I need a specific configuration file for using the BarCode.Android library on Android?

Yes, you need to specify the configuration file for the Android bundle in your .csproj file, typically named 'BundleConfig.json', to ensure native libraries are uncompressed.

How can I generate and save a barcode using IronBarcode in a MAUI application?

You can use the BarcodeWriter class to create a barcode from text input, determine the format (PDF or PNG), and then save it using a method like SaveToDownloadsAsync for Android and iOS.

What file formats are supported for saving generated barcodes in IronBarcode?

IronBarcode allows barcodes to be saved in PDF or PNG formats, based on the user's choice in the application.

How does IronBarcode help in processing QR codes in a .NET MAUI Android app?

IronBarcode facilitates QR code creation and reading through the QRCodeWriter class, enabling functionalities like generating QR codes from input text and reading barcode data from files.

Is there a sample project available for getting started with IronBarcode in .NET MAUI?

Yes, you can download a complete .NET MAUI App project with the example code provided in the guide to get started quickly.

What functionalities does IronBarcode provide for reading barcode data from files?

IronBarcode can read barcodes from image and PDF files using the BarcodeReader class, with results formatted and displayed accordingly in the application.

Curtis Chau
Technical Writer

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.

...
Read More

Ready to Get Started?

Nuget Downloads 2,422,100Version:2026.9just released

Get your free 30-day Trial Key instantly.
No credit card or account creation required
C# NuGet Library for PDF
Install with NuGet

Version: 2026.9

PM > Install-Package BarCode
nuget.org/packages/BarCode/
  1. In Solution Explorer, right-click References, Manage NuGet Packages
  2. Select Browse and search "IronBarCode"
  3. Select the package and install
C# PDF DLL
Download DLL

Version: 2026.9

  1. Download and unzip IronBarCode to a location such as ~/Libs within your Solution directory
  2. In Visual Studio Solution Explorer, right click References. Select Browse, "IronBarCode.dll"

Licenses from $999

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
Book your free Live Demo
Booking Badge

Trusted by Millions of Engineers Worldwide

Iron Software's customer logos
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required