Articles in this section
Category / Section

How to integrate .NET MAUI Barcode Generator with android native embedding application?

2 mins read

In this article, you’ll learn how to create a .NET MAUI Barcode Generator within a native embedded Android application by following these steps:

Step 1:
Create a .NET Android application and install the Syncfusion.Maui.Barcode NuGet package using nuget.org.

Step 2:
Add <UseMaui>true</UseMaui> to the project file to enable .NET MAUI support.

<PropertyGroup>
   <Nullable>enable</Nullable>
   <ImplicitUsings>enable</ImplicitUsings>
   <UseMaui>true</UseMaui>
</PropertyGroup>

Step 3:
Create a MauiAppBuilder and initialize .NET MAUI using the UseMauiEmbedding function. Build a MauiApp and create a MauiContext from it.

MauiContext? _mauiContext;

protected override void OnCreate(Bundle? savedInstanceState)
{
   base.OnCreate(savedInstanceState);
   MauiAppBuilder builder = MauiApp.CreateBuilder();
   builder.UseMauiEmbedding<Microsoft.Maui.Controls.Application>();
   builder.ConfigureSyncfusionCore();
   MauiApp mauiApp = builder.Build();
   _mauiContext = new MauiContext(mauiApp.Services, this);
}

Step 4:

Create a Grid and initialize the Barcode Generator with the QR code symbology, then add it to the Grid.

protected override void OnCreate(Bundle? savedInstanceState)
{
   ...
   Grid grid = new Grid();
   SfBarcodeGenerator barcode = new SfBarcodeGenerator();
   barcode.Value = "https://www.syncfusion.com/";
   barcode.HeightRequest = 200;
   barcode.WidthRequest = 200;
   barcode.Symbology = new QRCode();
   grid.Children.Add(barcode);
   ...
}

Step 5:

Convert the grid with the Barcode Generator to a platform-specific view and set it as the content view for the Android activity.

protected override void OnCreate(Bundle? savedInstanceState)
{
   Android.Views.View view = grid.ToPlatform(_mauiContext);

   // Set our view from the "main" layout resource.
   SetContentView(view);
}

Output:

BarcodeGenerator.png

Download the complete sample from GitHub.

Conclusion:
I hope you enjoyed learning how to integrate the .NET MAUI Barcode Generator with an Android native embedding application.

You can refer to our .NET MAUI Barcode Generator feature tour page to learn about its other groundbreaking feature representations. Explore our .NET MAUI Barcode Generator documentation to understand how to present and manipulate data.

You can check out our .NET MAUI from the License and Downloads page for current customers. If you are new to Syncfusion®, try our 30-day free trial to check out our .NET MAUI Barcode Generator and other .NET MAUI components.

Please let us know in the comments section if you have any queries or require clarification. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied