1

开发了以下源代码,用于使用 BLE 从一台 Android 设备向另一台 Android 设备发送消息:

public static String SERVICE_STRING = "6exxxxxx-xxxx-xxxx-xxxx-xxxxxdcca9e";
public static String CHARACTERISTIC_ECHO_STRING = "6eyyyyyy-yyyy-yyyy-yyyy-yyyyycca9e";

List<BluetoothGattService> serviceList = bluetoothGatt.getServices();

在检查服务列表时,在 Realme 5 Pro(Android OS 9.0,BLE v5.0)上与另一台设备建立成功连接后,服务列表没有返回带有上述服务字符串的特定服务,因此以下代码(BluetoothGattService)返回为 null ,因此无法通过 BLE 将数据发送到另一台设备。

BluetoothGattService service = findService(serviceList);
if (service == null) {
    Log.i("Null service", "Null service.");
    return matchingCharacteristics;
}

private static BluetoothGattService findService(List<BluetoothGattService> serviceList) {
        for (BluetoothGattService service : serviceList) {
            String serviceIdString = service.getUuid()
                    .toString();
            if (matchesServiceUuidString(serviceIdString)) {
                return service;
            }
        }
        return null;
    }

private static boolean matchesServiceUuidString(String serviceIdString) {
        return uuidMatches(serviceIdString, SERVICE_STRING);
    }

相同的源代码正在返回带有提到的服务字符串的服务列表,用于其他设备,如 Mi 4a(Android OS 7.0,BLE 4.0),Realme 3i(Android OS 9.0,BLE 4.2),对于它们,BluetoothGattService 实例正在返回不为空的详细信息,因此能够将消息发送到其他设备。

有没有人在使用 Android OS v9.0 和 BLE v5.0 的设备时遇到同样的问题?

4

0 回答 0