简体   繁体   中英

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.

BLE device stays connected to a phone until there are at least one connected app. So basically "disconnect" means disconnect of GATT client, not a full disconnect of BLE device from phone. Works same for both Android and 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. Native Android or iOS solutions are welcome, as I can write small library just for force disconnect feature.

Background info

Plugin.BLE disconnect implementation on Android calls both device.disconnect method and gatt.close method.

Plugin.BLE disconnect implementation on iOS calls centralManager.CancelPeripheralConnection method.

Both are disconnecting only current app but not a BLE device from phone.

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. After my all apps receive the message from BLE device they take it as a command to disconnect.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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