Developing with .NET MAUI on Zebra Android™ Devices

Nicola De Zolt -
6 MIN READ

Summary

EMDK support for Xamarin has been offered for years . Xamarin however is being sunset and a new framework is replacing it: .NET MAUI . This blog will walk you through how to migrate to MAUI using the currently available library from Zebra.

MAUI is in the news

So, in a few lines you've read about EMDK, Xamarin, MAUI but... - first things first - what is MAUI and why should you care about it?
You can learn more about MAUI from Microsoft's documentation, but if you're just looking for a quick summary:

  • .NET Multi-platform App UI (.NET MAUI) is a cross-platform framework for creating native mobile and desktop apps with C# and XAML
  • Using .NET MAUI, you can develop apps that can run on Android, iOS, macOS, and Windows from a single shared code-base

And - what's probabily most interesting to you is that -

  • .NET MAUI is open-source and is the evolution of Xamarin.Forms

That said, it's important for developers to understand if and when Zebra will be moving the EMDK support to MAUI. The good news is:

  • At Zebra we are actively working on EMDK's porting to MAUI; you'll be notified on through this portal when the process completes
  • And, although not yet officially supported, you can use the EMDK with MAUI leveraging the information from this blog

Comparing MAUI to Xamarin architectures

The following diagrams show how the two architectures differ. Left side of the image is © by Microsoft, right side is © by me. image

A few facts on these diagrams:

  • .NET MAUI compares to Xamarin.Forms
  • .NET for Android compares to Xamarin Android
  • This blog is about using Zebra EMDK for Xamarin (Android) in the .NET for Android branch of a MAUI project
  • In a .NET MAUI app, you write code that primarily interacts with the .NET MAUI API (1); e.g. A Visual Studio .NET MAUI App image
  • .NET MAUI then directly consumes the native platform APIs (3)
  • In addition, app code may directly exercise platform APIs (2); e.g. A Visual Studio Android Application image

Setting up your MAUI dev env

Creating your first MAUI App with EMDK

For your convenience, I've shared a couple of project samples which work out of the box

  1. EMDK Maui Demo App - this demonstrates how to set a specific Display time-out from an Asset XML profile; it's also using the CommunityToolkit.Mvvm framework from Microsoft to communicate across layers.
  2. ProfileClockSample - this demostrates working with the EMDK profile manager by altering your device date and time in real time. Credit: Thanks to Pubudu Wijeyaratne and Mahesh Pitakotuwa

Relevant steps and code snippets are commented below.

ADDING THE ZEBRA EMDK FOR XAMARIN DEPENDENCY
To access the underlying MX features of a Zebra device, you need to add the EMDK to your project.
EMDK for Xamarin is published here, however, Visual Studio can manage it for you through the NuGet Package Manager in the Tools menu.

If you are adding EMDK to your project for the first time, then open the NuGet Package Manager and choose "Manage NuGet Packages for Solution...", then go to the Browse tab and type EMDK in the search box. Once the results are returned, click on the Symbol.XamarinEMDK item, select the correct project, install it, and finally accept the license until it appears under the Installed tab.

For the sample projects above, you'll find this step already completed. You may incur installation related issues however, so also check the TIPS section below.
image

As a reference, open the emdkMAUIapp sample app and check the Solution Explorer. You should see the Symbol.XamarinEMDK package listed under the net6.0-android31.0. Note that for this project you need .NET 6 and the Android SDK 31 installed.
image

THE SOURCE CODE
To master the sample project you just need to focus on the following source code files in the Android branch of Platforms:

  • MainPage.xaml: defines the user interface, it's unique for all the target platforms, describes the UI in xml style
  • MainPage.xaml.cs: holds the code-behind of the graphic UI components
  • MainActivity.cs: is the main activity of the Android branch, includes the classic OnCreate method
  • Assets/EMDKConfig.xml: used for EMDK Profile APIs, can also be hosted under project root
  • AndroidManifest.xml: holds the permission settings and basic android and EMDK declarations

image

ACCESSING THE Symbol.XamarinEMDK NAMESPACE FROM YOUR CODE
Stick to the EMDK usage recommendation from our docs

  • In the MainActivity.cs
    • add a using Symbol.XamarinEMDK;
    • declare and implement the proper EMDK interfaces like this
      image
    • emdkMAUIapp uses the EMDK feature types Profile, Version, Notification for testing purposes, in async mode
    • the EMDK is initialized with a call to EMDKManager.GetEMDKManager() in the OnPostCreate method
    • Version and Notification feature types are finally consumed in the OnStatus method
    • the Profile feature type instead calls a further callback when finished, the ProfileManager_Data() method, where you can send the results to the UI layer.
  • As mentioned before, communication across objects is achieved via a Messenger bus, the WeakReferenceMessenger; see this link from Microsoft Learn for reference.
    • For instance a message from the Android platform specfic code can be sent to the XAML interface just calling
      WeakReferenceMessenger.Default.Send(sb.ToString());
    • This is received in the code-behind previously-registered callback
      image

TIPS

Working across several development environments and OS platforms, I sometimes face minor issues when dealing with the EMDK setup. The most annoying one occurred when the EMDK NuGet package was apparently well installed for the project, but the build failed, and the intellisense complained the EMDK library cannot be found
e.g. image

A way to fix this is as follows:

  • remove the currently install EMDK NuGet package

    • either by removing it from the Visual Studio solution explorer
    • or - if the last step didn't work - double click the project name in the solution explorer and delete the entry manually
      image
  • you also need to manually remove the NuGet folder from your disk. Do like this:

    • in Windows File Explorer, open the NuGet install folder usually found at C:\Users\/username/\.nuget\packages
    • inside that folder, enter the symbol.xamarinemdk subfolder and remove the 8.0.0.2 folder
      image
  • then close Visual Studio and restart it in Administrator mode and re-install the EMDK NuGet package

  • for this issue to be fixed, the Symbol.XamarinEMDK.dll must be found in
    image

Sometimes it might be useful to also check there is no active network filters preventing downloads from certain locations and certificate validation.

Conclusions

I've shown you the basic steps to migrate your Xamarin Forms applications to .NET MAUI, from a EMDK perspective. As mentioned above, though such process is not yet supported, it allows developers to move on and take advantage of the latest MAUI features and get ready for the official release. For more on this subject, stay tuned!
Happy Coding
Nicola

profile

Nicola De Zolt

.

Please Register or Login to post a reply

5 Replies

C Chris Sarotte

Hi Nicola - we have a customer very interested in .NET MAUI development, but they are concerned that it's not supported it yet. Do you happen to know when Zebra plans to announce official support?
Thank you - Chris

N Nicola De Zolt

Hi Chris, the current plan is to release it by the end of April 2023. Stay tuned for any updates! Thanks for your interest in Zebra EMDK for .NET MAUI.

J Jonathan Pugh

Any update on expected release dates for .Net Maui support for RFID SDK and EMDK? This is really needed and it is the end of April 2023 right now.

If there is no release of Maui compatible drivers for Zebra, is the best alternative to use the DataWedge? The documentation is really lacking especially with regard to using DataWedge with RFID. Are there any real world examples of controlling RFID with trigger events and getting RSSI power levels reported through DataWedge? My app needs to use both barcode and RFID scanning.

N Nicola De Zolt

Hi, The EMDK for Xamarin (EMDK-X) now supports the Microsoft .NET Multi-platform App UI, better known as MAUI. Please visit https://techdocs.zebra.com/emdk-for-xamarin/8-0/guide/maui/ for a full migration guide.

N Nicola De Zolt

Hi MAUI Developers! Here you can get a new sample of Zebra DATAWEDGE working on .NET MAUI https://github.com/ZebraDevs/datawedge-MAUI-SampleApp/.

 

Also, a developer faced some issues with the MAUI platform and commanding Datawedge - see my answers here https://github.com/ZebraDevs/datawedge-MAUI-SampleApp/issues/1