问题描述
蓝牙LE设备可以将消息广播到其他设备.该消息包可以包含长度,配置文件,rssi(信号强度)等信息.
Bluetooth LE devices can broadcast messages to other devices. That message packet can include informations like length, profile, rssi (signal strength), etc.
在Android中扫描BLE设备时,如何读取那些Bluetooth LE广播数据?
How can I read those Bluetooth LE broadcast data when scanning for BLE devices in Android?
推荐答案
API级别21 +
在 android.bluetooth.le.ScanCallback 中,以下回调方法具有名为 result 的参数,该参数具有名为 scanRecord 的字段,其中应包含BLE设备发送的广告数据.
In android.bluetooth.le.ScanCallback, the callback method as follows has a parameter named result, which has a field called scanRecord, with should contain the advertisement data sent by a BLE device.
void onScanResult (int callbackType, ScanResult result)
API级别18-20
在 BluetoothAdapter.LeScanCallback 中,以下回调方法具有名为 scanRecord 的参数,该参数应包含BLE设备发送的广告数据.
In BluetoothAdapter.LeScanCallback, the callback method as follows has a parameter named scanRecord, which should contain the advertisement data sent by a BLE device.
public abstract void onLeScan (BluetoothDevice device, int rssi, byte[] scanRecord)
scanRecord::远程设备提供的广告记录的内容.
scanRecord: The content of the advertisement record offered by the remote device.
这篇关于扫描时如何在Android中读取Bluetooth LE广告数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!