android 连接ble

最近在做一个ble midi的智能硬件项目,现把一些知识点记录如下:
首先由  bluetoothAdapter.startLeScan(leScanCallback) 去搜索,该方法接受一个callback去让开发者设置相应的代码。一旦有结果就运行callback里面的代码
我们来从log中看看是如何一步步执行的

BluetoothAdapter: startLeScan(): null
BluetoothAdapter: onClientRegistered() - status=0 clientIf=5
//扫描得到了结果发现了一个设备
BluetoothAdapter: onScanResult() - Device=C8:FD:19:9F:F4:BB RSSI=-59
//开始连接设备
BluetoothGatt: connect() - device: C8:FD:19:9F:F4:BB, auto: true
//注册该运行的app,这一步应该和之前的蓝牙配对一样
BluetoothGatt: registerApp()
//注册得到了一个uuid
BluetoothGatt: registerApp() - UUID=88590452-d8e7-4f6d-9ab7-aef15c6d4e62

BluetoothGatt: onClientRegistered() - status=0 clientIf=6

BluetoothGatt: onClientConnectionState() - status=0 clientIf=6 device=C8:FD:19:9F:F4:BB



由上面可以发现用的是蓝牙的 GATT协议进行通信

猜你喜欢

转载自ycljf86.iteye.com/blog/2371707