如何解决蓝牙断开连接时间太长
我可以连接到我的蓝牙设备,当我想断开连接时,大约需要 30 秒才能断开连接,并在几秒钟内断开连接并在后台自动重新连接到设备我不希望这种情况发生,怎么办我从字面上断开它? 我处理服务和设备并将其拉为空,但这不起作用
这是断开连接方法:
public bool disConnect()
{
try
{
IsScannerActiwe = false;
Buttonpressed = false;
IsConnected = false;
if (currentSelectedGattCharacteristic != null && currentSelectedService != null)
{
currentSelectedGattCharacteristic.Service?.dispose();
currentSelectedService?.dispose();
currentSelectedGattCharacteristic = null;
currentSelectedService = null;
if (bluetoothLeDevice != null)
{
bluetoothLeDevice.dispose();
bluetoothLeDevice = null;
return true;
}
}
}
catch (System.Exception ex)
{
Trace.WriteLine("Exception Handled -> disConnect: " + ex);
}
return false;
}
我处理设备和服务并将其拉为空,该函数返回true但它不会断开连接并且它为空几秒钟并且服务继续在后台自动运行
public async Task<bool> ClearBluetoothLEDevice()
{
if (IsConnected)
{
IsScannerActiwe = false;
Buttonpressed = false;
IsConnected = false;
// Need to clear the CCCD from the remote device so we stop receiving notifications
var result = await currentSelectedGattCharacteristic.WriteClientCharacteristicConfigurationDescriptorAsync(GattClientCharacteristicConfigurationDescriptorValue.None);
if (result != GattCommunicationStatus.Success)
{
return false;
}
else
{
if (currentSelectedGattCharacteristic != null)
{
currentSelectedGattCharacteristic.ValueChanged -= CurrentSelectedGattCharacteristic_ValueChanged;
IsConnected = false;
currentSelectedService.dispose();
currentSelectedGattCharacteristic.Service.dispose();
currentSelectedService?.dispose(); //added code
currentSelectedService = null; //added code
bluetoothLeDevice?.dispose();
bluetoothLeDevice = null;
currentSelectedGattCharacteristic = null;
return true;
}
}
}
return false;
}
我确实无法与设备断开连接
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。