如何在不使用任何库的情况下检测 android 中的 IBeacon
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23546371/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to detect IBeacon in android without using any library
提问by Likhit Jagatiya
i am new to Ibeacon and i want to know can we detect Ibeacon in android without using any SDKLibrary or library can any one give sample example.
我是 Ibeacon 的新手,我想知道我们是否可以在不使用任何 SDKLibrary 或库的情况下检测 android 中的 Ibeacon 任何人都可以给出示例示例。
i know some library like Radius Networks. but i don't want to use any library
我知道一些图书馆,如 Radius Networks。但我不想使用任何图书馆
回答by davidgyoung
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.
Android 操作系统没有任何检测 iBeacon 的代码,但它确实具有允许您扫描蓝牙 LE 设备的代码,这些设备是比 iBeacon 更低级别的设备。
You can roll-your own code that detects iBeacons using this Bluetooth LE scanning. That's exactly what the Android iBeacon Libraryfrom Radius Networksdoes. 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.
您可以使用此蓝牙 LE 扫描滚动检测 iBeacon 的自己的代码。这正是Android的iBeacon显示库从半径网络一样。它是开源的,因此如果您不想使用该库,您可以简单地从库中复制代码块并进行自己的检测。
The source code is here: https://github.com/RadiusNetworks/android-ibeacon-service
源代码在这里:https: //github.com/RadiusNetworks/android-ibeacon-service
EDIT:the library has been moved to http://github.com/AltBeacon/android-beacon-library
编辑:该库已移至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
如果你只是想玩这个,我会专注于库中的一个类: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)
这个类可以将Android蓝牙LE扫描记录转换为IBeacon(如果扫描的蓝牙设备确实是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
您可以在此处阅读有关如何在 Android 上设置蓝牙 LE 扫描的信息:http: //developer.android.com/guide/topics/connectivity/bluetooth-le.html
回答by Elias
There is a new small library: https://github.com/inthepocket/ibeacon-scanner-android
有一个新的小库: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.
如果没有库,扫描 iBeacon 非常容易,您只需要基于 iBeacon 创建正确的 ScanFilter,然后开始 BLE 扫描。创建正确的 ScanFilter 一开始可能很困难,最好查看上述库中的代码。
Dependant on Android version, location needs to be turned on, location permission needs to be granted and bluetooth, always, needs to be on.
取决于 Android 版本,需要打开定位功能,需要授予定位权限,并且需要始终打开蓝牙。