How to Manage iBeacon Scanning using Mesosfer – Part 2

This tutorial is about How to Manage iBeacon Scanning using Mesosfer

Table of Contents

  1. 1. Tutorial (Continued)
    1. 1.1. Define beacon cloud data
    2. 1.2. Beacon model
    3. 1.3. Download beacon data
    4. 1.4. Check phone state
    5. 1.5. Scanning beacon
    6. 1.6. Manage scanning results

1. Tutorial

This tutorial was the 2nd part of How to Manage iBeacon Scanning using Mesosfer.

1.1. Define beacon data

Go to your Mesosfer app -> Base -> Beacon, add this beacon below :

You can also define your own beacon parameters to match beacon device you have.

1.2. Beacon model

Create the package com.eyro.mesosfer.beacon.model. This package will store the classes for the model handling.

Class Beacon need to implement Parcelable because we need to use this parameters to use across the activity.

1.3. Download beacon data

Open SplashActivity class. We need to download beacon data from Mesosfer Cloud when splash screen has been showing up.

Here is the activity_splash.xml :

1.4. Check phone state

Before we start to scanning beacon, we need to check phone state :

– Bluetooth Low Energy support, this lines below will check whether Android phone support for BLE or not. If not, show alert dialog error.

– Bluetooth state (on/off), this lines below will check whether Android phone bluetooth is on. If it is off, show dialog to enable bluetooth.

– Location service state (on/off) when it comes to Android 5.0 or higher.

But if you want to check all state in one, you can use SystemRequirementManager. This will do check all state that require to enable beacon scanning, plus it will automatically show dialog when some state is disabled. Check all phone state like this lines below :

1.5. Scanning beacon

Open MainActivity class. After displaying splash screen and downloading beacon data from cloud, we need to check phone state and manage scanning within MainActivity. This time, we’ll create a dedicated property to hold the beacon region, since we’ll be using it in two places: to start, and to stop monitoring. This goes inside the MainActivity class:

Now, the code to start and stop monitoring as the activity appears and disappears on screen. You need to implement CBServiceListener before connecting to service. This also goes inside the MainActivity class:

1.6. Manage scanning results

Having the list pre-sorted by the Cubeacon SDK, and with all the prep work we’ve performed, the monitoring listener turns out to be quite simple :

The complete code for MainActivity class :

It’s done. We will continue this tutorial on Part-3.

Lead Mobile Software Engineer. Having more than 8 years in IT Consultant. Love working with new mobile platform technology. Expert in Android and iOS Mobile Development.