Connected devices

Background BLE on Android: why scans stop and what works

By Zawar Nadeem · Published Feb 24, 2026 · Updated Nov 18, 2026 · 5 min read

← All articles

Why Android BLE needs explicit state management

Android exposes a common BLE API across devices, but the application still has to deal with process lifetime, permissions, peripheral firmware, radio conditions, and vendor-specific behavior. A connection that works on a Pixel beside the peripheral is not evidence that it will recover on a Samsung after the app spends an hour in the background.

More delays and retries won't fix this. You need a connection model with explicit states and deadlines, tested on the devices you actually support.

A BLE connection as explicit states with deadlines
A BLE connection as explicit states with deadlinesEach step has a deadline. Once connectGatt has been called, any timeout, error or link loss drops to Disconnected, which closes that BluetoothGatt and bumps the connection generation so its late callbacks are ignored, then retries with bounded backoff. Reconnecting by address skips the scan only if the device's address is stable or it is bonded, and Android throttles apps that start scans too often (about five starts in 30 seconds), so a retry loop that rescans can silently find nothing. Bluetooth switched off or a revoked permission is not retryable: wait for the user instead of burning retries.Scantime limitConnectdeadlineDiscoverservicesMTUuse resultSubscribenotify onReadystream, opsany timeout, error or link lossDisconnectedclose(), gen + 1Backoffbounded retrieslimitFailedtell the userretry (scan only if needed)
Each step has a deadline. Once connectGatt has been called, any timeout, error or link loss drops to Disconnected, which closes that BluetoothGatt and bumps the connection generation so its late callbacks are ignored, then retries with bounded backoff. Reconnecting by address skips the scan only if the device's address is stable or it is bonded, and Android throttles apps that start scans too often (about five starts in 30 seconds), so a retry loop that rescans can silently find nothing. Bluetooth switched off or a revoked permission is not retryable: wait for the user instead of burning retries.

Scanning: make it bounded and purpose-specific

Android's BLE scanning guidance recommends stopping as soon as the target is found, never scanning in a loop, and setting a time limit because scanning is battery-intensive. Use a ScanFilter when the protocol gives you a stable service UUID or manufacturer-data signature. Device names are a weaker identifier because they may be absent, duplicated, or changed by firmware.

Android throttles an app that starts more than five scans in 30 seconds, without reporting an error. A scan left running for about 30 minutes is downgraded to opportunistic. Since Android 8.1, unfiltered scans pause while the screen is off, so a scan that must run with the screen off needs a non-empty ScanFilter.

If discovery must wake a process that is not running, investigate a filtered PendingIntent scan or CompanionDeviceManager. A timer that repeatedly starts scans is not a substitute for choosing the background API that matches the product.

Connection management: coordinate asynchronous operations

Characteristic and descriptor operations are asynchronous: the call starts work and a later callback reports its outcome. Starting another operation before the current one completes can make application state ambiguous and may cause an initiation call to be rejected.

For protocols that exchange a sequence of reads, writes, and descriptor changes, use an application-level queue scoped to the current connection. Advance it from the corresponding callback, and treat an operation that was not accepted for initiation as a failure rather than waiting for a callback that will not come.

A queue makes protocol order explicit. You still have to handle failed starts, disconnects and timeouts.

MTU: negotiate, observe, then size packets

The default ATT MTU is 23 bytes, leaving 20 bytes for a notification or write payload after the ATT header. Requesting a larger MTU does not guarantee that value. The application must use the result delivered to onMtuChanged and keep the peripheral's own limits in mind.

A GATT operation queue with deadlines
A GATT operation queue with deadlinesOne queue per connection. If Android refuses to start an operation, fail it and start the next. If a callback misses its deadline, don't start the next one: the request may still be pending in the stack, and an ATT transaction that times out (after 30 seconds) leaves the link unusable. Tear the connection down, fail everything pending and reconnect. Repeated refusals mean the stack and the queue are out of step; treat them the same way.Enqueue opthis connectionStart head opread or writeokAwait callbackwith a deadlineCompleteadvance queuenext oprefusedFail this opthen next opdeadlineTear down linkclose, gen + 1Fail pendingthen reconnect
One queue per connection. If Android refuses to start an operation, fail it and start the next. If a callback misses its deadline, don't start the next one: the request may still be pending in the stack, and an ATT transaction that times out (after 30 seconds) leaves the link unusable. Tear the connection down, fail everything pending and reconnect. Repeated refusals mean the stack and the queue are out of step; treat them the same way.

There is also a platform-version detail worth encoding in tests: the current BluetoothGatt.requestMtu documentation states that Android 14 and higher request an ATT MTU of 517 when the first GATT client asks, then disregards later MTU requests for that ACL connection. Do not build packet sizing around the integer passed into requestMtu.

Diagnosing a status 133 failure

Status 133 (0x85, GATT_ERROR in the AOSP stack) is a non-specific failure. It does not identify a root cause by itself. Bonding state, overlapping connection attempts, link loss, peripheral firmware and device-specific behavior are all hypotheses to test.

Status 133 tells you an operation failed and nothing more. Capture the preceding state, close the stale BluetoothGatt, and retry only when the product can do so safely.

Bound the retries and expose the terminal state to the user. Without the preceding events, radio state, device model, and peripheral logs, “GATT 133” does not tell you which layer failed.

Background BLE: choose the API from the user-visible task

A continuous, user-visible data session may justify a foreground service with the connectedDevice type and its required permissions. Discovery, reconnect, and short data transfers have different options. Android's current background BLE guidance covers filtered PendingIntent scans, WorkManager, auto-connect, and companion-device APIs.

Do not assume that a boot receiver can always restart a foreground service or that requesting exemption from battery optimization fixes every vendor policy. Model what must happen after process death, test the relevant Android versions, and explain any user action in the context of a feature the user has explicitly started.

Vendor power-management differences

Some device builds apply additional power-management controls. Test the shipping OS builds used by customers, but do not force every user through vendor-specific settings before a failure is observed. When intervention is necessary, explain the affected feature, open only supported settings surfaces, and verify the result.

A private catalogue of undocumented settings intents is brittle. Keep the normal lifecycle correct first: reconnect from explicit user intent, persist resumable state, use the appropriate foreground-service type, and make process death recoverable.

Testing: include real devices

Use physical hardware for end-to-end BLE behavior and maintain a matrix based on customer devices and Android versions. A programmable development kit can reproduce protocol states, but final acceptance still needs the production radio, firmware, antenna, enclosure, and body placement.

An application-level boundary around platform BLE

A product with several BLE workflows can benefit from keeping scanning, connection state, operation coordination, MTU results, and recovery policy behind one application-level boundary. Kotlin coroutines and StateFlow are one implementation option; the important part is that callbacks update a testable state model rather than unrelated screens managing the same connection independently.

Keep platform-version and device-specific handling close to that boundary, and keep the product protocol explicit above it. A small application with one short BLE interaction may not need the same abstraction as a long-running multi-sensor product.

If you are debugging a BLE product, contact DEVSFLOW with the peripheral, Android versions, and failure trace. Those details are more useful than a general description of an unreliable connection.