fix:调整蓝牙搜索时判断搜索到的设备是否配对的逻辑

This commit is contained in:
liyi 2025-05-12 13:57:50 +08:00
parent 310062513b
commit 4a725be23f

View File

@ -319,22 +319,34 @@ class BlueManage {
bool _isMatch(List<String> serviceUuids, {DeviceType deviceType = DeviceType.blue}) {
final List<String> prefixes = getDeviceType(deviceType).map((e) => e.toLowerCase()).toList();
for (String uuid in serviceUuids) {
final String cleanUuid = uuid.replaceAll('-', '').toLowerCase();
final String cleanUuid = uuid.toLowerCase();
if (cleanUuid.length == 8) {
// 8
// 845
String pairStatus = cleanUuid.substring(4, 6); // 4534
for (final prefix in prefixes) {
if (cleanUuid.startsWith(prefix)) {
return true;
// 00=01=
if (pairStatus == '00') {
return true; // true
}
// 01trueuuid
}
}
} else if (cleanUuid.length == 32) {
} else {
// 128834
final String first8 = cleanUuid.substring(0, 8);
if (first8.length >= 4) {
final String thirdAndFourth = first8.substring(2, 4); // 23
if (cleanUuid.length >= 32) {
final String thirdAndFourth = cleanUuid.substring(2, 4); // 23
for (final prefix in prefixes) {
if (thirdAndFourth == prefix) {
return true;
// UUID的第31321
if (cleanUuid.length >= 32) {
String pairStatus = cleanUuid.substring(30, 32); // 31321
// 00=01=
if (pairStatus == '00') {
return true; // true
}
// 01trueuuid
}
}
}
}