To develop applications with Xamarin, you first need to setup the Visual Studio for Xamarin development environment. I already had an existing Android environment so if you don't, you may need to install Android SDK before you can build your Android application.
Get Visual Studio for Xamarin
Download and install the Visual Studio tools for Xamarin. When the Visual Studio is installed you should see something like this.
Create the Library Binding
Before you can use our SDK from your Xamarin application, you need to create, what Xamarin calls a Binding Library. Once that library is created, you can consume it from a client application.
Create new Binding Project
Choose "New Project..." and from the list of available project types select Android -> Library. Then choose "Bindings Library" as the new project type.
Select the location of the new project and give it a descriptive name.
Download IndoorAtlas Android SDK
At the time of writing this, we don't know if there is a more elegant way of referencing an AAR file to bind, so the AAR file needs to be downloaded locally. The officially released IndoorAtlas Android SDK libraries are distributed via Bintray so open this link and download the latest version (or older version). You can download the ZIP, which contains all distribution files, but the AAR file is enough for this purpose.
Add IndoorAtlas SDK to Your Project
In the Visual Studio, go under Jars folder and choose Add Files....
Browse into the location where you downloaded IndoorAtlas Android SDK AAR file and select it. The Visual Studio may ask if you wish to copy the file into the project or reference it. I chose to copy under the project. This is how your project should look now. Also, double check that the Build action is set to LibraryProjectZip.
Configure Target Framework
Visual Studio needs to know the Android framework version the IndoorAtlas SDK AAR was build against. IndoorAtlas SDK 2.7.0 for Android was built against API 23, Marshmallow. Double click your binding project to bring up the Project Options dialog.
Build the Binding Project
Right click the project and choose Build
If you chose an Android framework which was not previously installed, Visual Studio will prompt you to download it. The build may generate several warnings. Most of these are related to obfuscated code and can be ignored for now. When the build succeeds, you should find the generated DLL in the bin/Debug directory under your binding project.
Build the Client Application
Now that we have create the binding for IndoorAtlas Android SDK, we can consume that from a client application.
Create a New Android Application
We'll add a new project under the same solution...
... and choose Android App as the project type.
Give it a descriptive name and hit Create.
Reference Binding Library
We need to tell Visual Studio that we want to use the IndoorAtlas Xamarin Binding Library we created in first step. Edit the project references.
And choose our binding library under the Projects tab.
You can now double click the imported binding library to verify that all important IndoorAtlas classes are available.
Setup Application for Indoor Positioning
Since the wrapping that Visual Studio produces in C# is very very close to our Java library for native Android, you can follow our standard documentation on how to setup IndoorAtlas' indoor positioning for Android.
In short those steps are:
- Add IndoorAtlas API key & secret to AndroidManifest.xml
- For Android >= 6, you need to ask for permissions listed in the AndroidManifest.xml at runtime, see https://docs.microsoft.com/en-us/xamarin/android/app-fundamentals/permissions?tabs=vswin#runtime-permission-checks-in-android-60
- Initializing IALocationManager when Activity is created
- Destroying IALocationManager when Activity is destroyed
- Registering for location updates when Activity is resumed
- Unregistering from location updates when Activity is paused
I also added two TextView widgets, one to display the status of IndoorAtlas positioning and another to display the currently detected location. Now my MainActivity.cs looks like this:
Run the App
After deploying the app into a real Android device and starting it the UI should look like this. The first TextView displays the current status (see actual API documentation to translate the codes) and the second TextView display the currently detected location as a string.
Same application in a short video for non-believers.
Now you should have basic idea how to use IndoorAtlas SDK with Xamarin. Please check our related documents on how to use IndoorAtlas iOS SDK with Xamarin. Happy coding!