Android BLE connection drops: what status 8, 19 and 22 mean and how to fix them
Why Android BLE connections drop: what disconnect statuses 8, 19, 22 and 0x3D mean, how to tell them apart, and a reconnect policy that works.
When an Android BLE connection drops, the status in onConnectionStateChange says who ended it: 8 means the link timed out (range, interference or a device reset), 19 means the device disconnected on purpose, and 22 means the phone's own Bluetooth stack ended it, often after a pairing or encryption problem. Close the old BluetoothGatt, then reconnect according to the status instead of with one retry loop for everything.
Key takeaways
- The disconnect status is a reason code: it tells you which side ended the link, not why.
- Status 8 is a supervision timeout. Check range, RSSI before the drop, and whether the device reset.
- Status 19 sends you to the firmware: idle timeouts, single-connection limits, reboots after OTA.
- Status 22 and 0x3D usually point at pairing and encryption, often a stale bond.
- Reconnect per status, with backoff, and log the status, the time connected and the phone model every time.
A connection that works for a while and then drops is the most common BLE bug report I get. Users call it “disconnects randomly”. It's rarely random. Android tells you who ended the link in the status of onConnectionStateChange, and with a few more facts logged around it, most drops fall into one of four groups.
What do the Android disconnect statuses mean?
When a connection ends, Android calls onConnectionStateChange(gatt, status, STATE_DISCONNECTED). For a disconnect, the status is mostly the HCI reason code from the Bluetooth controller, passed through as a number:
| Status | Name | Who ended it | Usual causes |
|---|---|---|---|
0 | GATT_SUCCESS | Your app | You called disconnect(), or something in your code did |
8 | GATT_CONN_TIMEOUT | Nobody: the link was lost | Out of range, body or wall in the way, interference, device reset or brown-out, supervision timeout too short |
19 | GATT_CONN_TERMINATE_PEER_USER | The device | Firmware idle timeout, only one connection allowed, reboot after an update, the device rejecting what the app did |
22 | GATT_CONN_TERMINATE_LOCAL_HOST | The phone's stack | Pairing or encryption failure, stale bond, the stack closing a link no client is using |
34 | GATT_CONN_LMP_TIMEOUT | Nobody: a procedure hung | Device didn't answer a link-layer procedure (parameter update, PHY update, encryption) |
61 (0x3D) | MIC failure | The controller | Encrypted packets failed their check: keys don't match, almost always a stale bond |
133 | GATT_ERROR | Unclear | As a disconnect, often right after connecting; see GATT 133 |
Type any code into the lookup below if yours isn't in the table.
Tool
GATT status code lookup27 codes
| Dec | Hex | Name | Meaning | Check first |
|---|---|---|---|---|
| 0 | 0x00 | GATT_SUCCESSany | Success. With STATE_DISCONNECTED it usually means your app asked for the disconnect. | Nothing, unless you didn't call disconnect(): then look for code that does. |
| 1 | 0x01 | GATT_INVALID_HANDLEoperation | The attribute handle doesn't exist on the device. | Stale GATT cache after a firmware update: rediscover services, or have the device send Service Changed. |
| 2 | 0x02 | GATT_READ_NOT_PERMITTEDoperation | The characteristic can't be read. | Check its properties in the GATT table; you may need notifications instead. |
| 3 | 0x03 | GATT_WRITE_NOT_PERMITTEDoperation | The characteristic can't be written, or not with this write type. | Compare WRITE vs WRITE_NO_RESPONSE in the characteristic's properties. |
| 5 | 0x05 | GATT_INSUFFICIENT_AUTHENTICATIONoperation | The device wants an authenticated (paired) link for this attribute. | Bond first, or let Android start pairing; wait for BOND_BONDED before retrying. |
| 6 | 0x06 | GATT_REQUEST_NOT_SUPPORTEDoperation | The device doesn't support this request. | Check the firmware handles the operation (e.g. long writes, reliable writes). |
| 7 | 0x07 | GATT_INVALID_OFFSEToperation | A read or prepared write used an offset past the end of the value. | Long reads/writes and their offsets; usually a protocol or firmware bug. |
| 8 | 0x08 | GATT_CONN_TIMEOUTconnection | The link was lost: no packets within the supervision timeout. Out of range, device reset, interference. (In an operation callback, 8 is GATT_INSUFFICIENT_AUTHORIZATION.) | Range and RSSI before the drop, device resets, supervision timeout vs connection interval. Reconnect with autoConnect = true. |
| 13 | 0x0D | GATT_INVALID_ATTRIBUTE_LENGTHoperation | The value written is longer than the attribute allows. | Payload size vs MTU − 3, and the firmware's max length for that characteristic. |
| 15 | 0x0F | GATT_INSUFFICIENT_ENCRYPTIONoperation | The attribute needs an encrypted link. | Bonding and encryption; a stale bond often shows up here. |
| 19 | 0x13 | GATT_CONN_TERMINATE_PEER_USERconnection | The device ended the connection on purpose. | Firmware: idle timeouts, a reboot after OTA, a single-connection limit, or rejecting your app's behavior. |
| 22 | 0x16 | GATT_CONN_TERMINATE_LOCAL_HOSTconnection | The phone's Bluetooth stack ended the link. | Pairing or encryption failures, a stale bond, or the stack closing a link no client is using. |
| 34 | 0x22 | GATT_CONN_LMP_TIMEOUTconnection | The device stopped answering a link-layer procedure (LL response timeout). | Firmware handling of connection-parameter updates, PHY updates or encryption; check with an HCI log. |
| 59 | 0x3B | UNACCEPTABLE_CONN_PARAMSconnection | The connection parameters were rejected. | Connection interval, latency and supervision timeout requested by the device or the app. |
| 61 | 0x3D | CONN_TERMINATED_MIC_FAILUREconnection | Encrypted packets failed their integrity check, so the link was dropped. | Almost always a key mismatch: a stale bond after the device was reset. Remove the bond and pair again. |
| 62 | 0x3E | GATT_CONN_FAIL_ESTABLISHconnection | The connection failed to be established: the device never answered. | Is it advertising and connectable? Range, a busy device, or another phone already connected. |
| 128 | 0x80 | GATT_NO_RESOURCESany | The stack ran out of resources. | Leaked BluetoothGatt clients or too many connections; close what you don't use. |
| 129 | 0x81 | GATT_INTERNAL_ERRORany | An internal error in the Bluetooth stack. | Usually a timing or state problem; serialize operations and retry once. |
| 130 | 0x82 | GATT_WRONG_STATEany | The operation isn't valid in the current state. | An operation sent before discovery finished, or after a disconnect. |
| 132 | 0x84 | GATT_BUSYany | Another operation is still running. | You need a GATT operation queue: one operation at a time, wait for each callback. |
| 133 | 0x85 | GATT_ERRORconnection | Android's generic failure: the connection didn't happen and no more specific code applied. | Time it: under a second points at leaked clients or the stack; ~30 s points at the device. Close every failed BluetoothGatt. |
| 135 | 0x87 | GATT_ILLEGAL_PARAMETERoperation | A parameter in the request was invalid. | Values, lengths and write types passed to the API. |
| 137 | 0x89 | GATT_AUTH_FAILany | Authentication failed during pairing. | Wrong passkey, the user cancelled, or the device and phone disagree on security level. |
| 143 | 0x8F | GATT_CONNECTION_CONGESTEDoperation | The link is congested; slow down. | Wait for onCharacteristicWrite before the next write without response. |
| 147 | 0x93 | GATT_CONNECTION_TIMEOUTconnection | A connection attempt ran out of time (newer stacks). | Treat like 133 after ~30 s: is the device advertising and in range? |
| 201 | 201 | ERROR_GATT_WRITE_REQUEST_BUSYAPI 33+ | BluetoothStatusCodes: a write was rejected because another request is in flight. | Queue your operations; never write before the previous callback arrived. |
| 257 | 0x101 | GATT_FAILUREany | A generic failure. | Log the operation and state around it; often a firmware rejection or stack problem. |
What to log on every disconnect
A status alone isn't enough to fix anything. Log these with it, every time, and you'll be able to sort field reports in minutes:
- The status and the time since the connection was established. A drop after 2 seconds and a drop after 40 minutes are different bugs.
- The last RSSI you read (
readRemoteRssi()every few seconds is cheap). A drop at -95 dBm is range; at -50 dBm it isn't. - The last GATT operation before the drop, and whether it completed.
- Phone manufacturer, model, Android version, and whether the screen was on.
- The device's firmware version and, if the firmware can tell you, its reset reason on the next connect.
// one line per disconnect, enough to sort field reports ble.disconnect status=8 connectedFor=41.2s lastRssi=-93 lastOp=notify(0x0024) phone=samsung/SM-A546B android=14 screen=off fw=1.4.2 ble.disconnect status=19 connectedFor=60.0s lastRssi=-58 lastOp=none phone=google/Pixel 8 android=15 screen=on fw=1.4.2 // exactly 60 s: an idle timeout
Status 8: the link timed out
Status 8 means no packet got through within the supervision timeout, a value agreed when the connection was set up (often a few seconds). Both sides give up and report the link as lost. That's what happens when the user walks away, puts the phone in a back pocket next to the device's antenna, or the device resets.
How to tell the causes apart:
- Weak RSSI before the drop: range. Nothing to fix in code except reconnecting gracefully, and maybe the device's TX power or antenna.
- Good RSSI, drop at a random time: the device may have reset. Ask the firmware team for a reset-reason register and read it after reconnecting.
- Drops right after a connection parameter change: the supervision timeout may be too short for the interval and latency. The spec requires it to be longer than
(1 + peripheral latency) × connection interval × 2, and in practice it needs a good margin above that. - Drops only with the screen off on some brands: check the phone's battery optimization first. Some vendors are aggressive with Bluetooth when the app isn't in a foreground service.
The fix on the app side: close the old BluetoothGatt and reconnect with autoConnect = true, which waits for the device without a timeout and connects when it's back.
Status 19: the device ended it
19 means the peripheral sent a disconnect on purpose. The app can't stop that, but it can usually find out why. The most common reasons:
- An idle timeout in the firmware. If drops happen at a suspiciously round time after the last activity (30 s, 60 s), that's it. Either keep the link busy on purpose or agree a longer timeout with the firmware team.
- The device only accepts one connection and another phone, or another app on the same phone, took it.
- A reboot after a firmware update or a configuration write. Expected, so the app should know to wait and reconnect, not show an error.
- The firmware rejecting something: a write it considers invalid, a missing authentication step, or a protocol version it doesn't support.
Add one real case: which device, what the drop pattern looked like and what the cause turned out to be (no client names).
Status 22 and 0x3D: usually pairing and keys
22 means the phone's stack ended the connection itself. In my experience the most common trigger is security: the device asked for encryption, pairing failed or keys didn't match, and Android dropped the link. Status 61 (0x3D, “MIC failure”) is more specific: encrypted packets failed their integrity check, which means the two sides have different keys. That's the classic stale bond after a device was reset or reflashed while the phone kept its old pairing.
Android can also tear down a link that no app is using anymore, a short while after the last BluetoothGatt on it was closed. If you see 22 shortly after your own code closed a client, check that you didn't close the one you still needed.
For stale bonds, decide with the firmware team how a reset device re-pairs, and detect the case in the app so you can tell users what to do. More in Android BLE bonding problems.
A reconnect policy that follows the status
One retry loop for every disconnect is how apps end up hammering a device that is rebooting, or never reconnecting after a timeout. Map the status to a decision instead:
sealed interface Reconnect {
data object Background : Reconnect // autoConnect = true, no timeout
data class After(val delayMs: Long) : Reconnect // direct connect after a pause
data class Stop(val reason: String) : Reconnect // tell the user, don't retry
}
fun policyFor(status: Int, userRequested: Boolean, attempt: Int): Reconnect = when {
userRequested -> Reconnect.Stop("user disconnected")
status == 8 -> Reconnect.Background // lost link: wait for it
status == 19 -> Reconnect.After(backoff(attempt, base = 2_000)) // device ended it, maybe rebooting
status == 22 || status == 61 ->
if (attempt < 1) Reconnect.After(1_000) else Reconnect.Stop("pairing problem")
status == 133 || status == 62 -> Reconnect.After(backoff(attempt, base = 600))
else -> Reconnect.After(backoff(attempt, base = 1_000))
}
private fun backoff(attempt: Int, base: Long) =
(base shl attempt.coerceAtMost(5)).coerceAtMost(30_000)Around it, the rules from GATT 133 still apply: close() the old BluetoothGatt on every disconnect, never reuse it, and keep one connection attempt in flight at a time. If you need the link to survive the screen turning off, run it from a foreground service; see background BLE on Android.
Add a result you can share, e.g. "field disconnects per user-day down X% after per-status reconnects and longer supervision timeout".
FAQ
What does status 8 mean in Android BLE?
Status 8 is GATT_CONN_TIMEOUT: no packet got through within the connection's supervision timeout, so the link was considered lost. The usual causes are range, obstacles, interference or the device resetting. Reconnect with autoConnect = true.
Why does my BLE device disconnect after exactly 30 or 60 seconds?
A drop at a round number of seconds after the last activity is almost always an idle timeout in the device's firmware, reported on Android as status 19. Agree a longer timeout with the firmware team or keep the link active.
What is the difference between disconnect() and close() on Android?
disconnect() ends the connection but keeps the BluetoothGatt client registered; close() releases it. After a disconnect you don't plan to resume on the same object, call close(), or the phone eventually runs out of clients and connections fail with 133.
Should I reconnect automatically after every BLE disconnect?
No. Reconnect according to the status: wait in the background after a timeout (8), pause and retry after the device ended it (19), and stop and tell the user after repeated pairing failures (22, 0x3D). Never reconnect after the user disconnected.