39

I'm looking for a way to detect iBeacon (iOS 7.0 feature) from an Android device. I read the Android documentation, where it seem that the iBeacon is some kind of GATT server which sends its position. While the Android documentation says that I should not poll that data, but for the detection this would be nessesary.

I google a lot but this topic is quite new (I even created a new tag ) so I would be happy if I get some links to ressources from the iOS world which descripes the implementation. Also if there are some Android libs which I did not find yet would be nice.

indivisible
  • 4,892
  • 4
  • 31
  • 50
rekire
  • 47,260
  • 30
  • 167
  • 264
  • I am not very familiar with the iOS platform but can it support a BTLE server or just a client? It turns out that the Android BTLE only supports a client even though the documentation suggests it can support a server. One can actually create a server, but it cannot advertise. – Brian Reinhold Aug 09 '13 at 12:39
  • iOS supports a server. If you take a look at the now-public AirLocate sample (in particular ALConfigurationViewController) from WWDC 2013, you can see how they're setting up the server to advertise. The actual code to advertise is deep within Apple's proprietary code, so it'd be difficult to replicate on Android, but it's totally doable to set any iOS app up as an iBeacon. – DesignatedNerd Sep 23 '13 at 00:46
  • Which devices did you use? This would be really interesting. – MrningLemn Mar 26 '14 at 17:00
  • A HTC one it need at least Android 4.3 and Bluetooth low energy see also http://developer.android.com/guide/topics/connectivity/bluetooth-le.html please note this is the answers section so please delete this "comment". – rekire Mar 26 '14 at 17:04
  • I have a Google Nexus 10. Just updating it to Android 4.2.2 and next is 4.3. That should work too, right? – MrningLemn Mar 26 '14 at 17:32
  • 4.2.2 will not work but 4.3 – rekire Mar 26 '14 at 17:33

3 Answers3

66

EDIT: The library below has been moved here:

https://github.com/AltBeacon/android-beacon-library


I have ported the iOS7 iBeacon SDKs to Android, and was able to see standard iBeacons and estimate their range. The code is available here:

https://github.com/RadiusNetworks/android-ibeacon-service

For this to work, you need Android 4.3 which introduced the Low Energy Bluetooth APIs. You also need a device with a low energy bluetooth chipset.

If you don't want to use the full library above, you can roll your own. iBeacons simply transmit a BLE advertisement once per second that start with a known sequence of bytes. You simply have to tell Android to do a BLE scan, get each advertisement, and look for one that starts with the known iBeacon byte sequence. You can then parse out the iBeacon fields. Here is the code the shows how this is done:

https://github.com/RadiusNetworks/android-ibeacon-service/blob/master/src/com/radiusnetworks/ibeacon/IBeacon.java#L177-L231

davidgyoung
  • 63,876
  • 14
  • 121
  • 204
  • 1
    Would http://developer.samsung.com/ble work for earlier Android versions? I'm going to find out for myself (hopefully sooner rather than later), but thought I'd pose the question here too. – Mark Peterson Oct 22 '13 at 18:14
  • No, the Samsung BLE SDK is a completely different implementation than the one native to Android 4.3. In theory it would be possible to create a version of the Android iBeacon Library that works with Samsung BLE SDK, but it would involve rewriting much of it. Given that most if not all Samsung devices with BLE will probably get an upgrade to Android 4.3 in the next several months, it just isn't worth the effort to port the Android iBeacon Library for the Samsung BLE SDK. – davidgyoung Oct 22 '13 at 19:19
  • @MarkPeterson very interested to know if you are able to get it to work with earlier versions. – b-ryce Oct 23 '13 at 13:49
  • Do you know if it is possible to look for beacons in the background like you can do in iOS 7? – Yves Oct 28 '13 at 12:57
  • Yes, it is possible. You have to start the IBeaconService in a way that it does not get stopped when your Activity shuts down. – davidgyoung Oct 28 '13 at 14:02
  • I was able to use the samsung.com/ble examples to pair/connect with an ble instance that I set up on a linux, also opened an rfcomm (not ble) session with it to write some text. I'm still trying to create a gatt server (which I'm assuming that is what iBeacon is most similar to). Honestly, I'm still trying to determine up from down with Bluetooth development. Bluetooth LE development is very light on examples. That's a bad thing and a wonderful thing :) – Mark Peterson Nov 05 '13 at 22:24
  • Just got a GATT server/service running with bleno.js library (https://github.com/sandeepmistry/bleno it's only a week old, so be gentle). And yes, I was able to connect and read le service characteristics with Samsung BLE library using their sample applications http://developer.samsung.com/ble. The heart rate sample app was the simplest to play around with for proof of concept. Samsung Galaxy S4, Android 4.2.2. – Mark Peterson Nov 08 '13 at 00:59
  • @DavidYoung, Finally got NEXUS 7 and your library seems working. Thanks for providing this library and sharing sources and your findings. – bob Dec 02 '13 at 22:04
  • 2
    For @MarkPeterson and others looking for support on Samsung devices runing 4.2.x, this is now possible. See here: https://github.com/davidgyoung/android-beacon-library/tree/samsung-ble-sdk – davidgyoung Sep 01 '14 at 11:55
2

The only catch here is to detect beacon even the app is not running. Unlike iOS7, it is not natively support. In iOS7, when you on your BT, it will automatically notify you when you enter the region of registered iBeacon.

I had implemented iBeacon in Android 4.3 API using IntentService plus AlarmManager. To do a scan every 30 sec( to save your battery power, it shall be longer). It works well for user. Only when the matching uuid/major/minor is found, then it will trigger notifications. Otherwise, it will sleep and wake up for scanning again.

i think this is the solution for your question.

Alfred Loh
  • 87
  • 6
0

I didn't quite get what you mean, could you provide links to the documentation which said that you should not poll the data?

But it seems to me that the iBeacon is working as a server, which is kind of funny to me. Isn't it meant to find other devices, not the phone itself?

https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.position_quality.xml

This is the characteristics it uses though. To me it sounds like that the devices you are looking for are the "beacons" and the phone itself is just a listener. So you would not poll the EHPE and EVPE data but you should actually listen to it's changes or "broadcasts".

I'm kind of new to this myself also and couldn't find any really specific documentation.

Though, be advised, in the link I provided there is download link in the top corner which will provide you the full documentation in PDF format. There you will probably find more answers.