简体   繁体   English

Android \\ iOS强制BLE设备断开所有应用程序的连接

[英]Android\iOS force BLE device disconnect for all apps

I have multiple Xamarin apps that use Plugin.BLE they are simultaneously connected to a same BLE device. 我有多个使用Plugin.BLE的 Xamarin应用程序,它们同时连接到同一BLE设备。

BLE device stays connected to a phone until there are at least one connected app. BLE设备保持与手机的连接,直到至少有一个已连接的应用程序。 So basically "disconnect" means disconnect of GATT client, not a full disconnect of BLE device from phone. 因此,基本上,“断开连接”意味着断开GATT客户端的连接,而不是将BLE设备与电话完全断开连接。 Works same for both Android and iOS. 适用于Android和iOS。

I'm looking for a way to forcefully disconnect BLE device from phone from one app, so it will be detected as "disconnected" or at least "connection lost" from all other apps. 我正在寻找一种从一个应用程序强制将BLE设备与手机断开连接的方法,因此它将被检测为与所有其他应用程序“断开连接”或至少“连接断开”。 Native Android or iOS solutions are welcome, as I can write small library just for force disconnect feature. 欢迎使用本机Android或iOS解决方案,因为我可以编写仅用于强制断开功能的小型库。

Background info 背景信息

Plugin.BLE disconnect implementation on Android calls both device.disconnect method and gatt.close method. Android上的Plugin.BLE断开连接实现同时调用device.disconnect方法和gatt.close方法。

Plugin.BLE disconnect implementation on iOS calls centralManager.CancelPeripheralConnection method. iOS上的Plugin.BLE断开连接实现调用centralManager.CancelPeripheralConnection方法。

Both are disconnecting only current app but not a BLE device from phone. 两者都仅断开当前应用程序的连接,而不会断开BLE设备与手机的连接。

I didn't find a way to force disconnect in a way I wanted. 我没有找到一种以我想要的方式强制断开连接的方法。 As I understand it is intended by design, but in my opinion it is weird that I can disconnect ALL devices by turning off Bluetooth adapter but cannot entirely disconnect one specific device. 据我了解,这是设计意图,但我认为我可以通过关闭蓝牙适配器来断开所有设备的连接,但不能完全断开一台特定设备的连接,这很奇怪。

My solution was to use BLE device itself to broadcast message to all apps that use it and belong to me. 我的解决方案是使用BLE设备本身向使用该设备并属于我的所有应用程序广播消息。 After my all apps receive the message from BLE device they take it as a command to disconnect. 当我所有的应用程序从BLE设备收到消息后,他们将其作为断开连接的命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM