android 蓝牙4.0 ble随笔

蓝牙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 设置特征字。

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容