集成FastBle
1、在app/build.gradle 添加依赖:
implementation 'com.github.Jasonchenlijian:FastBle:2.4.0'
2、个人习惯通过镜像去拉取依赖包,所在在项目的build.gradle配置:
repositories {
maven {
url 'https://maven.aliyun.com/repository/google' }
maven {
url 'https://maven.aliyun.com/repository/jcenter' }
maven {
url 'https://maven.aliyun.com/nexus/content/groups/public/' }
google()
jcenter()
mavenCentral()
}
在此不对FastBle接入已经初始化使用说明,仅补充fastble文档中没有详细说明如何获取uuid等操作。
private String serviceUuid; //uuid_service
private String descriptorUuid; //描述符 UUID
private List<String> charUuid = new ArrayList<>(); //特征值 UUID
//一般的蓝牙设备都会有几个特征值 UUID和描述符 UUID
private void discoverUuids(BluetoothGatt gatt) {
charUuid.clear();
// 遍历所有服务
for (BluetoothGattService service : gatt.getServices()) {
// 获取服务 UUID
serviceUuid = service.getUuid().toString();
Log.d