Android support for iBeacons is, at the time of this writing, sketchy at best. There is no actual support for it directly in the Android SDK and only a handful of phone models have the hardware necessary to support the BLE technology used by iBeacons.
I have a project where we want to simply detect the presence of iBeacons and show some different UI in the app if one of “ours” is found. We’re not doing anything fancier than that, so it seemed a 3rd party library might be a reasonable option until the Android OS (or actually, hopefully the compatibility/support library) adds official support for it.
I decided to try the Radius Networks library because it seemed to be open source (or so I thought) and they seem to know what they are doing. However, the sample reference application steers you down a path that doesn’t end well - you can find iBeacons all right, but it doesn’t tell you anything about them. The library call to setMonitorNotifier
accepts a MonitorNotifier
which sounds promising - but doesn’t actually give you any information about the found beacon, and there wasn’t a way I could find to query the current beacons found.
So in order to actually see what beacon you have found (i.e., just get the major and minor numbers) you have to actually use their “ranging” API even if you don’t care about range. I got it to work like this:
First derive your activity from IBeaconConsumer
and RangeNotifier
. Then declare the beacon manager and initialize it in onCreate:
And that’s all you need to do - very simple, once you find it…