Combine iBeacon bluetooth low energy with Android 4.3
Asked Answered
C

3

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.

Chowchow answered 26/7, 2013 at 7:28 Comment(6)
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.Vivisect
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.Constantinople
Which devices did you use? This would be really interesting.Heraclid
A HTC one it need at least Android 4.3 and Bluetooth low energy see also developer.android.com/guide/topics/connectivity/… please note this is the answers section so please delete this "comment".Chowchow
I have a Google Nexus 10. Just updating it to Android 4.2.2 and next is 4.3. That should work too, right?Heraclid
4.2.2 will not work but 4.3Chowchow
P
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

Pyrognostics answered 26/9, 2013 at 21:53 Comment(9)
Would 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.Looselimbed
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.Pyrognostics
@MarkPeterson very interested to know if you are able to get it to work with earlier versions.Frantz
Do you know if it is possible to look for beacons in the background like you can do in iOS 7?Cynth
Yes, it is possible. You have to start the IBeaconService in a way that it does not get stopped when your Activity shuts down.Pyrognostics
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 :)Looselimbed
Just got a GATT server/service running with bleno.js library (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 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.Looselimbed
@DavidYoung, Finally got NEXUS 7 and your library seems working. Thanks for providing this library and sharing sources and your findings.Scission
For @MarkPeterson and others looking for support on Samsung devices runing 4.2.x, this is now possible. See here: github.com/davidgyoung/android-beacon-library/tree/…Pyrognostics
M
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.

Mendelsohn answered 17/1, 2014 at 2:56 Comment(2)
I've found repeated scans interfere with Blutooth audio. There has to be a better way than this.Philipps
altbeacon's library has a sample that includes launching an app. altbeacon.github.io/android-beacon-library/samples.htmlJoellyn
C
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.

Courtyard answered 31/7, 2013 at 11:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.