use*_*243 4 android bluetooth-lowenergy ibeacon
我正在尝试为Android开发BLE应用程序.
我可以通过哪种方式检测和读取Android设备上的信标的UDID,Major,Minor?
我已经阅读了RadiusNetworks android-ibeacon-service,但我无法理解为什么:
major = (256 * (0xFF & paramArrayOfByte[(i + 20)]) +
(0xFF & paramArrayOfByte[(i + 21)]));
Run Code Online (Sandbox Code Playgroud)
这paramArrayOfByte是LeScanCallback byte[] scanRecord
当你得到byte[] scanRecord从BluetoothAdapter.LeScanCallback,它将包括蓝牙LE头,它可以根据iBeacon显示的可变长.
由于可变长度头部,指示iBeacon广告(4c 00 02 15)的四个字节可以从第三个字节(scanRecord[2])到第六个字节()的任何地方开始scanRecord[5].在最新的代码中,Android的iBeacon显示图书馆发现的索引位置4c 00 02 15内scanRecord,并称其为startByte.其他所有东西都处于固定的位置startByte.
scanRecord应该被解析为AD结构列表.使用nv-bluetooth,您可以像下面这样提取iBeacon.
public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord)
{
// Parse the payload of the advertising packet.
List<ADStructure> structures =
ADPayloadParser.getInstance().parse(scanRecord);
// For each AD structure contained in the advertising packet.
for (ADStructure structure : structures)
{
if (structure instanceof IBeacon)
{
// iBeacon was found.
IBeacon iBeacon = (IBeacon)structure;
// Proximity UUID, major number, minor number and power.
UUID uuid = iBeacon.getUUID();
int major = iBeacon.getMajor();
int minor = iBeacon.getMinor();
int power = iBeacon.getPower();
........
Run Code Online (Sandbox Code Playgroud)
有关详细信息,请参阅" iBeacon作为一种AD结构 ".