BLE Disconnect
Summary
- Internal name:
Ble_disconnect - Category: Bluetooth
- Purpose: Close a previously opened BLE GATT connection, either for one specific device or for every connected device at once.
- Task type: Normal
Compatibility
-
Minimum AndroMate version:
1.1.0 -
Maximum AndroMate version:
1.1.0 -
Minimum Android:
Android 13 (API 33) -
Maximum Android tested:
Android 16 (API 36) -
Supported manufacturers:
- ✅ All manufacturers
-
Required permissions:
BLUETOOTH_SCANBLUETOOTH_CONNECT- Device location enabled (required by Android for BLE operations)
Detailed description
The BLE Disconnect task closes a GATT connection previously opened by Ble_connect. It can target one specific device by mac_ble, or every currently-connected BLE device at once via disconnect_all.
If the target device is already disconnected (or was never connected), the task does nothing and reports it as already disconnected.
Input parameters
| Parameter | Type | Required | Possible values | Android Compatibility | AndroMate Compatibility | Default |
|---|---|---|---|---|---|---|
mac_ble |
String | No¹ | A valid Bluetooth MAC address, e.g. AA:BB:CC:DD:EE:FF |
Android 13 (API 33) → Android 16 (API 36) | 1.1.0 → 1.1.0 | "" |
disconnect_all |
Boolean | No | true / false |
Android 13 (API 33) → Android 16 (API 36) | 1.1.0 → 1.1.0 | false |
¹ mac_ble is required only when disconnect_all is false (the default) — it's ignored when disconnect_all is true.
Output parameters
The BLE Disconnect task produces no outputs.
Exceptions
| Code | Exception Name | Description |
|---|---|---|
BLE-TASK-001 |
Bluetooth Not Enabled | Bluetooth is turned off on the device. |
BLE-TASK-002 |
Bluetooth Not Supported | This device does not support Bluetooth. |
ERROR-001 |
Permission Not Granted | BLUETOOTH_SCAN or BLUETOOTH_CONNECT was not granted. |
GPS-ERROR-003 |
Disabled Location Settings | Device location is disabled — required by Android for BLE. |
Execution flowchart
flowchart TD
Start([▶ Ble_disconnect]) --> Prereq{BLE enabled, supported,\npermissions, location OK?}
Prereq -->|No| E1[❌ BLE-TASK-001/002\nERROR-001/GPS-ERROR-003]
Prereq -->|Yes| Mode{disconnect_all?}
Mode -->|true| All[🔌 Disconnect every registered device]
Mode -->|false| One{mac_ble\nregistered?}
One -->|Yes| Single[🔌 Disconnect mac_ble]
One -->|No| Info[ℹ️ Log: already disconnected]
All --> Success([✅ VoidResult])
Single --> Success
Info --> Success
E1 --> Error([❌ Exception])
style Start fill:#e3f2fd
style Success fill:#c8e6c9
style Error fill:#ffcdd2
How it works:
- Prerequisite checks: Bluetooth enabled/supported, permissions granted, location enabled.
disconnect_all: true: disconnects every currently-registered BLE device.disconnect_all: false(default): disconnects onlymac_ble, if it's registered — otherwise logs it as already disconnected, no error.
Input parameter details
1. Input parameter: mac_ble
The Bluetooth MAC address to disconnect. Required unless disconnect_all is true.
Example
2. Input parameter: disconnect_all
When true, disconnects every currently-connected BLE device and ignores mac_ble.
Example
Details
- Optional — defaults to
false.