android 查看ble,检测BLE设备是否可在Android上连接

更新:对于Android O SDK中的最终API,ScanResult类(自Android 5.0添加)现在具有isConnectable()方法.只能在Android 8.0上检测可连接的广告.有关详细信息,请参阅此处:

https://developer.android.com/reference/android/bluetooth/le/ScanResult.html#isConnectable()

在Android 8.0之前,不幸的是它是不可能的.

可连接的广告由PDU标头字节0确定.您可以在下面的示例结构中看到这一点:

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

问题出在Anroid 8.0之前的设备上,Android扫描API无法访问这些标头.你在Android 4.x的回调中得到了三个字段:

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

扫描数据字节数组在上述头字节之后开始.从我所看到的BluetoothDevice定义中,没有任何字段或方法告诉您它是否是可连接的广告 – 该类只是蓝牙mac地址的容器,具有在蓝牙堆栈上运行功能的方法.并且IBluetooth.aidl中没有任何方法可以获得此标志,该方法是蓝牙堆栈的私有接口(以及BluetoothDevice调用以获取其信息的内容).

看来这些信息不会从Android 8.0之前的BlueDroid堆栈传递到Java层.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值