Xamarin Android – Quick start guide

In order to successfully integrate the Xamarin wrapper for Point SDK, you would require a Bluedot account. Please contact our sales team by requesting for a demo.  Also ensure that you also meet the Android requirements.

The Bluedot Point SDK enables geo-location capability for apps by delivering accurate location awareness, while substantially reducing battery consumption compared to Android Location API or other standard methods. The Point SDK connects to the Bluedot’s backend system, Point Access, to download your pre-configured Geofences, GEOLINE™, Bluetooth Beacons, conditions, and actions.

The Point SDK enables rapid development of location-aware apps. It delivers precise location awareness to the mobile application, but without the usual battery drain that would typically occur. There’s also no need for additional hardware, making it highly scalable. This means the Point SDK enables location-based apps and experiences that were previously impossible. The rest is up to you.

 


Step 1: Creating the Xamarin Android project

Create the Xamarin Android project:

1. Note: Ensure that your Visual Studio version is at least 15.3.

2. Start a new Xamarin Visual Studio solution, select Android App template and click Next.

3. Enter an App Name, Organization Name. Select Modern Development as target platforms and click Next.

4. Choose a folder to save the project (e.g. ‘Projects’) and select ‘Create’.

 


Step 2: Importing the Point SDK

1. Download the Xamarin Android Point SDK in the ‘Downloads’ section of the Point Access Dashboard.

2. Unzip the Xamarin Android Point SDK and add  BDPointXamarinBinder.dll as a reference to your project solution, by selecting .Net Assembly tab and browsing to BDPointXamarinBinder.dll location.

3. Once you add the BDPointXamarinBinder.dll in your project solution, it will appear in References.

 


Step 3: Update the AndroidManifest.xml

Bluedot Point SDK requires adding permissions and services in AndroidManifest.xml file.

1. Navigate to Properties folder in solution explorer and open the AndroidManifest.xml file. Select the Source viewing option to view the xml of the file.

2. Add following permissions under manifest tag

Permissions in AndroidManifest.xml

<!-- General Point SDK functionality --><uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<!-- Required for Beacons integration -->
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />

3. Add following services under application tag.

Services in AndroidManifest.xml
<!-- General Point SDK functionality --><service
 android:name="au.com.bluedot.point.net.engine.BlueDotPointService"
 android:exported="false">
</service>
 
<service android:name="au.com.bluedot.point.net.engine.DataJobScheduler"
 android:exported="false"
 android:permission="android.permission.BIND_JOB_SERVICE" />
 
<!-- Required for Beacons integration -->
<service
 android:name="au.com.bluedot.point.beacon.BlueDotBLEService"
 android:exported="false">
</service>


Step 4: Minimal Point SDK Integration

1. Declare an instance of ServiceManager class, which is the entry point for an app to start using Point SDK.

Declare ServiceManager instance
namespace appname
{
    [Activity(Label = "appname", MainLauncher = true, Icon = "@mipmap/icon")]
    public class MainActivity : Activity
    {
        ServiceManager serviceManager;
        ...
    }
}

2. Implement  IServiceStatusListener and IApplicationNotificationListener interfaces to register Bluedot Point SDK callbacks. Implement the member functions of the interfaces.

Point SDK Interface and Callbacks
namespace appname
{
    [Activity(Label = "appname", MainLauncher = true, Icon = "@mipmap/icon")]
    public class MainActivity : Activity, IServiceStatusListener, IApplicationNotificationListener
    {
        ServiceManager serviceManager;
        ...
 
 
        protected override void OnCreate(Bundle savedInstanceState)
        {
            ...
        }
 
        public void OnBlueDotPointServiceStartedSuccess()
        {
            // This is called when BlueDotPointService started successfully
            // Your app logic can start from here
        }
 
        public void OnBlueDotPointServiceError(BDError p0)
        {
             
            // This gives you details if BlueDotPointService encounters error.
            // Human-readable string of bdError.getReason() can be useful to analyse the cause of the error.
            // Boolean bdError.isFatal() identifies if error is fatal and BlueDotPointService is no more functional;
            // onBlueDotPointServiceStop() callback is invoked next in such a case.
        }
 
        
        public void OnBlueDotPointServiceStop()
        {
            // This will be called when BlueDotPointService has been stopped.
            // Your app could release resources that use the BlueDotPointService
        }
 
        public void OnCheckIntoBeacon(BeaconInfo p0, ZoneInfo p1, LocationInfo p2, Proximity p3, IDictionary<string, string> p4, bool p5)
        {
            // This will be called if the trigger happened on a Beacon
            // and the zone contains a custom action
            // Using runOnUiThread to interact with UI Elements within UI Thread
        }
 
        public void OnCheckIntoFence(FenceInfo p0, ZoneInfo p1, LocationInfo p2, IDictionary<string, string> p3, bool p4)
        {
            // This method will be called if the device checked into a Fence
            // and the zone contains a custom action
            // Using a handler to pass Runnable into UI thread to interact with UI elements
        }
 
        public void OnCheckedOutFromBeacon(BeaconInfo p0, ZoneInfo p1, int p2, IDictionary<string, string> p3)
        {
            // This method will be called when a device Checks out of a Beacon  
        }
 
        public void OnCheckedOutFromFence(FenceInfo p0, ZoneInfo p1, int p2, IDictionary<string, string> p3)
        {
            // This method will be called when a device leaves the Fence that was checked into. Only applies to zones flagged as checkout enabled on the backend
        }
 
        public void OnRuleUpdate(IList p0)
        {
            // Passively receive Zones information
        }
 
       ...
    }
}

3. Instantiate the ServiceManager singleton object and invoke SendAuthenticationRequest() function inside OnCreate() by passing the package nameAPI key, registered email and IServiceStatusListener reference, to request Point SDK Authentication.

namespace appname
{
    [Activity(Label = "appname", MainLauncher = true, Icon = "@mipmap/icon")]
    public class MainActivity : Activity, IServiceStatusListener, IApplicationNotificationListener
    {
        ServiceManager serviceManager;
        ...
 
 
        protected override void OnCreate(Bundle savedInstanceState)
        {
            ...
            serviceManager = ServiceManager.GetInstance(this);
            serviceManager.SendAuthenticationRequest("", "", "", this);
             
            ...
        }
 
 
       ...
    }
}

Step 5: Next Steps

Essential Guides:

Xamarin Android integration examples on GitHub 

You can refer to Xamarin Android integration examples via the link below:

GitHub Examples

API Documentation can be assessed via the link below:

API Documentation

Created by Bluedot DevOps on January 17, 2018

Start the discussion