Combine iBeacon bluetooth low energy with Android 4.3

霸气de小男生 提交于 2019-12-02 13:53:50

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

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!