Xamarin Binding

Introduction

This page provides instructions to create a Xamarin binding library project for the Workpath SDK. It assumes the reader has working knowledge of Visual Studio and Xamarin.

General information about Xamarin’s java binding concept is provided here:

https://docs.microsoft.com/en-us/xamarin/android/platform/binding-java-library/

The instructions to bind an Android .aar are located here:

https://docs.microsoft.com/en-us/xamarin/android/platform/binding-java-library/binding-an-aar

Setup Steps

  1. Create a new Bindings Library project (e.g. WorkpathBinding), starting with the Android Bindings Library template, as described in the ‘binding-an-aar’ reference.
  1. Once the project is created, the project template includes a Jars folder. Copy WorkpathLib.aar from the <Workpath SDK home folder>/Libraries to Jars folder in your project.

 

  1. Set the Build Action for WorkpathLib.aar to ‘LibraryProjectZip’.

 

 

  1. Edit Transforms/Metadata.xml to add:

<remove-node path="/api/package[starts-with (@name, 'com.hp.workpath.api') = false]" />

 

  1. Open the project Properties to configure the Applications settings. Set Android Class Parser to ‘class-parse’.

 

 

Note:

There is a known issue (https://developercommunity.visualstudio.com/content/problem/219595/class-parse-not-working-in-xamarin-android-binding.html), when setting ‘Android Class Parser’ via the Properties tab in Visual Studio 2017 versions. This issue manifests itself during the build, where the classes which inherit from or contain members of unresolvable types are skipped. A simple workaround of this issue is to add <AndroidClassParser>class-parse</AndroidClassParser> to your project file (.csproj) manually.

 

  1. Build your project, verify the output .dll is present in <Project Name>/bin/Debug/<Project Name>.dll.

 

Testing the Bindings Library

To consume the library, it must be added as a reference in your application project e.g. BindingTestApp.

  1. Right-Click the References node of your Application Project and select Add Reference...

 

  1. Select the binding project created earlier. e.g. WorkpathBinding

 

 

  1. Open the References node of your application project i.e. BindingTestApp to verify that the binding project i.e. WorkpathBinding reference is present.

 

 

  1. Double click the References to open it in the Object Browser. The content of the bindings library can be viewed:

 

  1. The method and types of the bindings library can be accessed, as any other C# methods and types.

 


protected override void OnCreate(Bundle savedInstanceState)
{
    base.OnCreate(savedInstanceState);

    // Initialize the Workpath Sdk
    Workpath.Instance.Initialize(this);

    // Workpath API access
    ScanAttributes.MeBuilder meBuilder = new ScanAttributes.MeBuilder();

    meBuilder.SetColorMode(ScanAttributes.ColorMode.Auto);
}

 

  1. Build and test your application!