蓝牙设备未断开连接

时间:2018-06-07 08:47:45

标签: android xamarin.android bluetooth-lowenergy

我正在开发Xamarin android原生应用程序,使用Plugin.BLE 1.3.0库连接蓝牙设备。实际上,我们的应用程序应具有以下功能,逐个连接多个蓝牙设备并逐个断开这些设备。

美观是,我们能够按预期逐个连接设备,但在断开此设备时我们遇到了问题。实际上,我有5个蓝牙设备,我试图逐个连接,然后逐个断开设备。

大部分时间它都是成功的,但很少有蓝牙设备没有断开连接且LED指示灯没有熄灭。

每当发生断开连接问题时,我都检查了蓝牙适配器实例,但是蓝牙适配器没有维护我们现在断开连接的设备信息。不知何故,蓝牙管理器(适配器)丢失了设备信息,并且仅在重新启动移动设备之后才保持连接状态,然后设备连接断开连接。

要连接设备,我调用以下代码:

bool UseAutoConnect = false;
CancellationTokenSource tokenSource = new CancellationTokenSource();
await    CrossBluetoothLE.Current.Adapter.ConnectToDeviceAsync(device, new 

ConnectParameters(autoConnect:UseAutoConnect,forceBleTransport:false),tokenSource.Token);

要断开设备连接,我打电话给以下代码:

await CrossBluetoothLE.Current.Adapter.DisconnectDeviceAsync(device);

如果我们有多个连接,你能否建议如何逐个处理断开设备?

配置: -

Version of the Plugin: Plugin.BLE
version="1.3.0" targetFramework="portable46-net451+win81"
https://github.com/xabre/xamarin-bluetooth-le

Platform:: Android API 21

Device: Samsung Tab S3, Google Pixel XL, Samsung Galaxy J7 Prime (Android 7.0)

0 个答案:

没有答案
相关问题