Alex MitrovicBLE & IoT app developer, Android and iOS

Permissions & scanning

BLE in the background on Android: scanning limits, Doze and foreground services

Why Android BLE scans and sync stop in the background: throttling, screen-off limits, Doze, vendor battery savers, and what to use instead.

Short answer

Android limits background BLE in several layers: more than five scan starts in 30 seconds are throttled, unfiltered scans stop while the screen is off, long scans are downgraded, Doze delays work, and some vendors kill background apps. Use filtered scans, PendingIntent scans or CompanionDeviceManager to find devices, and a foreground service of type connectedDevice to keep a connection alive.

Key takeaways

  • Never start and stop scans in a tight loop: five starts in 30 seconds and Android silently ignores the next one.
  • Always scan with a ScanFilter if you need results with the screen off.
  • A PendingIntent scan survives your process being killed; the system wakes you with results.
  • To keep a live connection in the background, use a foreground service with type connectedDevice.
  • Test on Samsung and Xiaomi phones with battery optimization on; that's where background BLE dies first.

“It works when the app is open” is the second most common BLE bug report after drops. Background BLE on Android isn't one limit but a stack of them, added over several releases, and on top of that each phone vendor has its own battery manager. Here they are in the order they bite, and what to use instead.

Which limits apply to BLE in the background?

LimitSinceWhat happensWhat to do
Scan start throttlingAndroid 7More than 5 startScan calls in 30 s: later ones silently don't startStart one long scan; don't restart it to “refresh” results
Long-running scansAndroid 7A scan running for about 30 minutes is downgraded to opportunisticUse filters and PendingIntent scans for long waits
Screen-off unfiltered scansAndroid 8.1Scans without a ScanFilter stop while the screen is offAlways pass at least one filter: service UUID, name or address
Background execution limitsAndroid 8Background services are stopped soon after the app leaves the foregroundForeground service, WorkManager, or system-delivered scan results
Doze and App StandbyAndroid 6Network, alarms and jobs are deferred when the phone is idlePlan for delays; don't rely on exact timing in the background
Foreground service typesAndroid 14A foreground service must declare a type and hold its permissionsconnectedDevice type + FOREGROUND_SERVICE_CONNECTED_DEVICE
Vendor battery saversAnySome phones kill or freeze background apps far more aggressivelyTest on those phones; guide users to exemptions only when needed

Finding devices in the background

There are three good ways to learn that a device is nearby without keeping your app awake:

1. A filtered scan with a PendingIntent

Since Android 8, startScan can take a PendingIntent instead of a callback. The system keeps scanning, using hardware filters where the chip supports them, and delivers matching results to a BroadcastReceiver, even if your process was killed in the meantime.

A background scan that survives process death
@SuppressLint("MissingPermission") // BLUETOOTH_SCAN checked before calling
fun startBackgroundScan(context: Context) {
    val filters = listOf(
        ScanFilter.Builder().setServiceUuid(ParcelUuid(MY_SERVICE_UUID)).build()
    )
    val settings = ScanSettings.Builder()
        .setScanMode(ScanSettings.SCAN_MODE_LOW_POWER)
        .setCallbackType(ScanSettings.CALLBACK_TYPE_FIRST_MATCH)
        .build()
    val intent = PendingIntent.getBroadcast(
        context, 1, Intent(context, ScanResultReceiver::class.java),
        PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE // the system adds results
    )
    context.getSystemService(BluetoothManager::class.java)
        .adapter.bluetoothLeScanner.startScan(filters, settings, intent)
}

The receiver gets the results in BluetoothLeScanner.EXTRA_LIST_SCAN_RESULT. Keep the work in it short: start a foreground service or enqueue work if you need to connect.

2. CompanionDeviceManager presence

If the app is associated with the device through CompanionDeviceManager, newer Android versions can tell your CompanionDeviceService when the device appears and disappears, and associated apps get exemptions for starting foreground services from the background. For single-device companion apps this is the most battery-friendly option.

3. autoConnect to a known device

For a device you've connected to before, connectGatt(context, true, …) registers a background connection that the controller completes when the device shows up. It only lives as long as your process, so combine it with a foreground service if the app must stay connected.

Keeping a connection alive

If the product needs a live link with the screen off (a sensor streaming data, a lock waiting for a command), the honest answer is a foreground service. It shows a notification, which is the point: the user can see the app is working for them.

Foreground service for a BLE connection (Android 14+ rules)
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_CONNECTED_DEVICE" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

<service
    android:name=".ble.DeviceConnectionService"
    android:exported="false"
    android:foregroundServiceType="connectedDevice" />

Two things trip people up. On Android 14+, starting the service with the connectedDevice type requires that you hold a matching runtime permission such as BLUETOOTH_CONNECT, or it throws. And since Android 12, apps mostly can't start a foreground service from the background, so start it while the app is visible, or rely on one of the exemptions (CDM association is one).

Periodic sync without a live connection

Many devices only need a sync now and then: a sensor with a day of readings, a lock's access log. Use WorkManager: a periodic job (15 minutes is the minimum) that connects, syncs and disconnects. It's deferred in Doze and batched with other work, so don't promise exact times, but it's kind to the battery and survives reboots.

Vendor battery managers

Stock Android is only half the story. Some vendors add their own “sleeping apps” lists, auto-start restrictions or aggressive task killers, and they differ between models and OS versions. dontkillmyapp.com keeps track of the known cases. My rule: first make the app work within the official rules (foreground service, filters, WorkManager), test on those phones, and only then, if a specific phone still kills it, show a short guide for that vendor's setting.

Add which phone brands gave you the most trouble in the background, and what you did about it.

FAQ

Why does my Android BLE scan stop when the screen turns off?

Since Android 8.1, scans without a ScanFilter are stopped while the screen is off. Add at least one filter, for example your device's service UUID, and the scan continues.

Why does startScan sometimes find nothing on Android?

If the app called startScan more than five times in 30 seconds, Android silently ignores further starts for a while. Start one scan and keep it running instead of restarting it to refresh results.

How do I keep a BLE connection alive in the background on Android?

Run the connection from a foreground service with foregroundServiceType="connectedDevice", declare FOREGROUND_SERVICE_CONNECTED_DEVICE, hold BLUETOOTH_CONNECT and show its notification. Start it while the app is visible.

Can my app get BLE scan results after it was killed?

Yes, with a PendingIntent scan: startScan with a PendingIntent keeps running in the system and delivers matching results to your BroadcastReceiver, starting your process if needed.

Sources

Seeing this in your own app?

Send me the phone models and what the logs say. On a short call I'll tell you where I'd look first.

Book a free call

Free · NDA on request · reply within 1–2 working days