Example app
Test UWP and WinUI App
To test the SDK a sample application is provided. You can download the sample source code for UWP here and WinUI here.
The example app has two buttons. The Test QR button reads a test mDL using server retrieval URL method (online). The QR is hardcoded and does not expire. The Scan QR button reads a device mDL using BLE (offline) after QR engagement. The QR is scanned with the PC webcam. After scanning, the data elements retrieved are shown in a datagrid. You can see a screenshot below
Update for version 1.1: The new ISO AAMVA fields are included as shown below
The code to perform the mDL retrieval is shown below.
public async Task HandleScanResult(string qrCode, bool bOnline = false)
{
var reader = MdlReader.Instance;
var ts = new CancellationTokenSource();
// if you want to cancel from UI call ts.Cancel()
// Get the path to the app's Certificates folder.
MdlReaderVM.LocalFolderPath = System.IO.Path.GetTempPath(); // ApplicationData.Current.LocalFolder.Path;
string path = Windows.ApplicationModel.Package.Current.InstalledLocation.Path + @"\Certificates";
string licenseText = @"bm..==";
string errorMessage = reader.Initialize(new ReaderSettings
{
DefaultRequestMode = RequestMode.All,
LicenseText = licenseText,
UserName = "Filippos",
EnableOnline = bOnline,
DebugEnabled = true,
CertificatesPath = path,
//SentryDsn = "https://...."
});
if (!string.IsNullOrEmpty(errorMessage))
{
await reader.MessageBox(errorMessage, true);
return;
}
MdlResponse response = await reader.RequestRead(qrCode, ts.Token);
if (!string.IsNullOrEmpty(response.ErrorMessage))
{ await reader.MessageBox(response.ErrorMessage); }
else
{
dataGrid1.ItemsSource = response.Items;
dataGridDS.ItemsSource = response.DSCertificateInfo;
if (response.IACACertificateInfo != null)
{ dataGridIACA.ItemsSource = response.IACACertificateInfo; }
else
{ dataGridIACA.Visibility = Visibility.Collapsed; }
securityChecksChk.IsChecked = response.SecurityChecksPassedOK;
}
if (response.Portrait != null && response.Portrait.Length > 0)
{
var img = await GetImageFromBytes(response.Portrait);
portraitImage.Source = img.ToNative();
}
}
public async static Task<IBitmap> GetImageFromBytes(byte[] bytes)
{
using (MemoryStream ms = new MemoryStream(bytes))
{
IBitmap image = await BitmapLoader.Current.Load(ms, null /* Use original width */, null /* Use original height */);
return image;
}
}
To compile the ExampleMdlReaderApp you have to: 1) Right click References, Click "Αdd reference" 2) Go to Project tab and uncheck all items 3) Go to Browse tab, click Browse... button, find the folder where you extracted the SDK zip and select the 3 dll files. 4) Right click the project -> Properties -> Package Manifest, On the Package.appxmanifest go to Packaging tab -> Choose Certificate, click "Select from file" -> ExampleMdlReaderApp_TemporaryKey.pfx (when asked for password enter 123456).