Now that I have a pair of beacons up and running, next step is to create an app to see how you can interact with them. For this sample, I will create an app using Xamarin Forms and I will test the app with Android as target (my iOS build and deploy environment is on Luis hands)
So, our Xamarin Forms Solution has multiple projects, a common project and the custom implementations for Android, iOS and Windows Phone. In each one of the projects you can add external components that will help us work with the beacons. A quick search shows us that we have several available Estimote NuGet packages to work with.
The first step is to add the Estimote SDK for Android into the Android project. A search of the components will show us this component.
The application that we will make will be a Xamarin Forms one, so if you also want to implement it in iOS you can add the component for iOS
There is a common NuGet Package which we must add into the Forms app, and in the Android and iOS, this package is ACR Estimote PlugIn for Xamarin
Let’s go back to the Android project, in this one we must enable permissions to work with BlueTooth
And now is time to add a couple of lines of code. In the main app, I’ll add a stack with 3 labels
- private Label _labelTitle;
- private Label _labelContent;
- private Label _labelStatus;
In the app Start(), I’ll init the interaction with the Beacons (line 48). If everything works properly, we can start to suscribe to the events Raged and RegionStatusChanged (lines 59 and 60)
When the app detects a beacon, we will receive a message with the same information. The beacons work with a concept that the regions are (see external links), a region can be defined with one or more beacons. The primary way of identifying them consists of 3 options
- With only UUID: it consists of all beacons with a given UUID. For example: a region defined with default Estimote UUID would consist of all Estimote Beacons with unchanged UUID.
- With UUID and Major: it consists of all beacons using a specific combination of UUID and Major. For example: all Estimote Beacons with default UUID and Major set to 13579.
- With UUID, Major and Minor: it consists of only a single beacon (Estimote Cloud prevents having two beacons with the same IDs). For example, one with default Estimote UUID, Major set to 13579 and Minor set to 2468.
In the RegionStatusChanged() event, we will capture the change of region. The new region will show us information of the UUID, Major and Minor.
With these few lines of code we can already test our app. At this time, we can deploy our app on the emulator. But at the same we will see that Visual Studio 2015 emulator does not support BlueTooth emulation.
So, in the next post I will show how the app on a real device.
Greetings @ Madrid
- El Bruno Estimote and Star Wars
- NuGet Estimote SDK for Xamarin Android
- NuGet Estimote SDK for Xamarin.iOS
- NuGet ACR Estimote PlugIn for Xamarin
- Estimote Beacons and Regions
Hello, I was wondering if your friend Luis ever did this for iOS. Is there a link where I can find this for iOS version?
the code should work the same in an iOS app. You only need to change the Xamarin component and use the iOS one instead of the android.