BLE中,设备分为中心设备(central)和外围设备(peripheral)
中心设备就是你的手机,外围设备就是智能手环一类的东西。开发BLE的应用都得遵守Generic Attribute Profile (GATT),一个BLE蓝牙设备包含多个service,每个service 又包含多个characteristic。每个characteristic有一个value和多个descriptor,通过characteristic中心设备与外围设备进行通信,charateristic起着载体的作用,通过writeCharacteristic()和readCharacteristic(),可以写入和读出信息。
不同service、characteristic和descriptor都有各自己唯一的UUID。
当连接上BLE设备后,调用discoveryServices()发现服务,通过SERVICE_UUID获取目标service,如果service不为空,* 再通过CHARACTERISTIC_UUID获取characteristic,借助characteristic写入指定值与BLE设备进行通信。
一个GATT服务表现为一个BluetoothGattService 对象,我们需要通过适当的UUID从 BluetoothGatt 实例中获得;
一个GATT特征表示为一个 BluetoothGattCharacteristic 对象,我们可以通过适当的UUID从BluetoothGattService 中得到;
一个GATT描述符表现为一个 BluetoothGattDescriptor 对象,我们可以通过适当的UUID从BluetoothGattCharacteristic对象中获得