Android 解码GattServices数据

Android 解码GattServices数据,android,bluetooth-lowenergy,Android,Bluetooth Lowenergy,我正在Android Studio中实现BLE。我已与外围设备连接正常。在我的OnServicesDiscoveryd方法中,我想分析服务(和特征),打印时得到如下结果: android.bluetooth。BluetoothGattService@41b6dd18 列表中有4项服务,除了末尾的数字外,它们看起来都很相似。如何将其转换为有用的信息。我没有看到对这种格式的引用 谢谢。尝试从BluetoothGattService对象读取uuid 您可以在上找到标准服务的uuid。如果uuid不存在

我正在Android Studio中实现BLE。我已与外围设备连接正常。在我的OnServicesDiscoveryd方法中,我想分析服务(和特征),打印时得到如下结果:

android.bluetooth。BluetoothGattService@41b6dd18

列表中有4项服务,除了末尾的数字外,它们看起来都很相似。如何将其转换为有用的信息。我没有看到对这种格式的引用


谢谢。

尝试从BluetoothGattService对象读取uuid


您可以在上找到标准服务的uuid。如果uuid不存在(即定制服务),则应阅读外设手册或联系外设制造商 BLE的工作原理主要类似于字典,在字典中查找长数字(特征)并获取二进制数据,因此,如果事先没有关于正在使用的设备的信息,那么在发现服务时就看不到多少

也就是说,在中,有一个方法
displayGattServices()
,它将发现的服务信息放在一个可扩展的列表视图中,这里我将其更改为将服务的UUID和特性打印到logcat

除了UUID之外,还可以使用查找其他特征属性,例如特征数据的格式,或者查看是否可以读取或写入特征

// Demonstrates how to iterate through the supported GATT
// Services/Characteristics.
private void displayGattServices(List<BluetoothGattService> gattServices) {
    final String TAG = "BleServiceInfo";

    if (gattServices == null) return;
    String uuid;
    String unknownServiceString = "Unknown service"
    String unknownCharaString = "Unknown characteristic"

    // Loops through available GATT Services.
    for (BluetoothGattService gattService : gattServices) {
        Log.d(TAG, "Service: " + gattService.getUuid().toString());

        // Loops through available Characteristics.
        for (BluetoothGattCharacteristic gattCharacteristic : gattCharacteristics) {
            Log.d(TAG, "\tCharacteristic: " + gattCharacteristic.getUuid().toString());
        }
     }
}

这看起来像一个访问地址,不像特征数据。
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
    ....

    displayGattServices(gatt.getServices()); 
}