My Companies

Monitoring iBeacons without an iOS device

As I already said in my previous post on iBeacons, you don't need an iOS device to monitor iBeacons. Sure, iOS comes with inbuilt support for monitoring and ranging beacons, but since beacons are plain Bluetooth LE devices that send out a periodic advertisement packet, all you need is something that can find Bluetooth LE devices. A compatible Android device, or even a simple bluetooth LE adapter like ConnectBlue OBS 421 will do just fine.

Lets talk about how we can find bluetooth devices using Android. Android 4.3 (API Level 18) introduces built-in platform support for Bluetooth Low Energy in the central role and provides APIs that apps can use to discover devices, query for services, and read/write characteristics.

// Use this check to determine whether BLE is supported on the device. Then
// you can selectively disable BLE-related features.
if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
Toast.makeText(this, R.string.ble_not_supported, Toast.LENGTH_SHORT).show();
finish();
}

To find the BLE devices, you would need to get the BluetoothAdapter, enable bluetooth and then start a scan.

This is where it starts to get interesting. Since, Android dosen't (yet) support the iBeacon specification, you need to manually parse the advertisement packet (scanData) to find the details about the scanned beacon. From StackOverflow,

Finding the distance (or accuracy as it is called) is a bit more involved. First thing that you will realize when managing beacons this way is that you cannot rely on just one measurement of RSSI. You need to keep a running average of RSSI values to get a reliable estimate and even that is not going to be super accurate and there's not much you can do about it.