android 蓝牙4.0 ble随笔

2020-05-25  本文已影响0人  多一点童真

蓝牙4.0 Ble 主要有以下BluetoothGatt,BluetoothGattService,BluetoothGattCharacteristic,BluetoothGattDescriptor ,BluetoothGattCallback 这几个类。

BluetoothGatt 用于连接,搜索ble设备,BluetoothGattService

是ble设备中的服务,ble可能有多个这样的服务,每个服务有指定uuid, 每个BluetoothGattService

中有BluetoothGattCharacteristic集合,

BluetoothGattCharacteristic 叫特征字,用于蓝牙之间的信息的通信,每个BluetoothGattCharacteristic 都有指定的uuid,

要找到指定的BluetoothGattCharacteristic,必须通过gatt

通过指定的uuid找到BluetoothGattService,再通过BluetoothGattService找到指定的BluetoothGattCharacteristic, 

BluetoothGattCharacteristic 通过setValue写数据,通过read写数据;

BluetoothGattCallback 是gatt连接后的回调类,回调方法onConnectionStateChange,用户监听蓝牙的连接状态;onServicesDiscovered 用户发现ble设备;onCharacteristicWrite 用于接受ble server 设备的返回值,也就是ble server设备向客户端写的值;onCharacteristicChanged 用于监听ble server 设备的返回值的变化,要此方法有回到必须gatt调用方法setCharacteristicNotification 设置特征字。

上一篇 下一篇

猜你喜欢

热点阅读