检测是否BLE装置可连接在Android [英] Detecting whether a BLE device is connectable on Android

查看:226
本文介绍了检测是否BLE装置可连接在Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个项目,配置信标。接通电源后,一定量的时候,一盏明灯变得不可配置,直到它被重新上电。为了显示配置标列表,我在看某些特性(蓝牙设备名称,在广告数据包的某些生产商的数据)。我还需要知道,如果它是连接,我。即如果在BLE广告包该设备的PDU类型指示它是可连接的。我搜索了Android蓝牙类高有低,无论是在安卓4.x和5.x以及一直没能找到任何东西,会告诉我这个信息。

I am working on a project for configuring beacons. A certain amount of time after being powered on, a beacon becomes unconfigurable until it is power-cycled. In order to show a list of the configurable beacons, I am looking at certain characteristics (Bluetooth device name, certain manufacturer data in the advertising packet). I also need to know if it is "connectable", i. e. if the PDU Type in the BLE advertising packet for the device indicates that it is connectable. I've searched the Android Bluetooth classes high and low, both in Android 4.X and 5.X and haven't been able to find anything that will tell me this information.

我认识的一个方法来确定信标连接性,最多可连接到它,E。 G.: device.connectGatt(...)。不过,我已经看到了它需要超过两分钟,有时一个回调 onConnectionStateChange 才回来与 STATE_DISCONNECTED 。此外,可以有许多这些信标中的环境的,并连接到每一个的可能的是可配置的效率是低

I realize that one way to determine the beacon connectability is to connect up to it, e. g.: device.connectGatt(...). However, I've seen it take over two minutes sometimes before a callback to onConnectionStateChange comes back with STATE_DISCONNECTED. Also, there may be many of these beacons in an environment, and connecting up to every single one that might be configurable would be inefficient.

在iOS的相当于该属性可以在 CBAdvertisementDataIsConnectable 中的关键<$的 advertisementData 词典中找到的C $ C> CBCentralManagerDelegate 回调方法 centralManager:didDiscoverPeripheral:advertisementData:RSSI

The iOS equivalent of this attribute can be found in the advertisementData dictionary under the key CBAdvertisementDataIsConnectable in the CBCentralManagerDelegate callback method centralManager:didDiscoverPeripheral:advertisementData:RSSI.

所以,问题是:有没有办法在Android确定BLE装置是否为连接的广告数据或扫描结果或...

So, the question is: is there a way on Android to determine whether or not a BLE device is "connectable" from advertising data or scan result or ... ?

推荐答案

不幸的是,我认为这是不可能的。

Unfortunately, I think it is not possible.

一个连接广告由PDU头字节0来确定你可以看到这个在下面的示例结构:

A connectable advertisement is determined by the PDU Header byte 0. You can see this in the example structure below:

d6 be 89 8e # Access address for advertising data (this is always the same fixed value)
40 # Advertising Channel PDU Header byte 0.  Contains: (type = 0), (tx add = 1), (rx add = 0)
24 # Advertising Channel PDU Header byte 1.  Contains:  (length = total bytes of the advertising payload + 6 bytes for the BLE mac address.)
05 a2 17 6e 3d 71 # Bluetooth Mac

现在的问题是,Android的扫描API可让您将这些标题没有访问权限。你得到确切的回调三个方面:

The problem is, the Android scanning APIs give you no access to these headers. You get exactly three fields in the callback:

onLeScan(BluetoothDevice device, rssi, byte[] scan data)

扫描数据的字节数组开始的上面提到的头字节。而从我所看到的 BluetoothDevice类的定义,没有任何字段或方法告诉你,如果它是一个连接广告 - 类仅仅是一个容器,蓝牙MAC有方法解决对蓝牙堆栈行使职能。还有在 IBluetooth.aidl 没有方法是专用接口的蓝牙堆栈(什么 BluetoothDevice类调用来得到它的信息),可以得到这个标志。

The scan data byte array starts after the header bytes mentioned above. And from what I can see of the BluetoothDevice definition, none of the fields or methods tell you if it is a connectable advertisement -- the class is just a container for the bluetooth mac address with methods to exercise functions on the bluetooth stack. And there are no methods in IBluetooth.aidl which is the private interface to the bluetooth stack (and what BluetoothDevice calls to get its info) that can get this flag.

看来,此信息不向上传递到Java层从BlueDroid堆栈。这些标志也许应该在另一个参数添加到 onLeScan 法获得通过,或列入 BluetoothDevice类类。但显然事实并非如此。

It appears that this information is not passed up to the Java layer from the BlueDroid stack. These flags should probably be passed in yet another parameter to the onLeScan method, or included in the BluetoothDevice class. But clearly they are not.

这篇关于检测是否BLE装置可连接在Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆