How to detect IBeacon in android without using any library

我是研究僧i 提交于 2019-12-02 19:44:08

The Android OS does not have any code that detects iBeacons, but it does have code that allows you to scan for Bluetooth LE devices, which are a lower-level device than an iBeacon.

You can roll-your own code that detects iBeacons using this Bluetooth LE scanning. That's exactly what the Android iBeacon Library from Radius Networks does. It is open source, so if you don't want to use the library, you can simply copy blocks of code out of the library and do your own detection.

The source code is here: https://github.com/RadiusNetworks/android-ibeacon-service

EDIT: the library has been moved to http://github.com/AltBeacon/android-beacon-library

If you detection use cases are very simple, this might work fine. Be careful not to bite off too much work, though, because handling all the edge cases can become increasingly complex. That's certainly what I learned when writing the library.

If you just want to play with this, I would focus on one class from the library: IBeacon.java

This class can convert from an Android Blueooth LE scan record to an IBeacon (if the scanned Bluetooth device is indeed an iBeacon)

You can read about how to set up Bluetooth LE scanning on Android here: http://developer.android.com/guide/topics/connectivity/bluetooth-le.html

There is a new small library: https://github.com/inthepocket/ibeacon-scanner-android

Without a library it's very easy to scan for ibeacons, you just need to create the correct ScanFilter, based on the iBeacon, and then start a BLE scan. Creating the correct ScanFilter can be hard at first, best have a look at the code in the mentioned library.

Dependant on Android version, location needs to be turned on, location permission needs to be granted and bluetooth, always, needs to be on.

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