stopBackgroundScan

fun stopBackgroundScan(pendingIntent: PendingIntent)

Stops an ongoing background BLE scan that was previously started with startBackgroundScan.

This method should be called when you no longer need to receive background scan results, such as when:

  • The user disables a feature that requires BLE discovery

  • The app has found the target device

  • The app is being uninstalled or reset

Important

  • You must pass the exact same android.app.PendingIntent instance (or an equivalent one with the same request code, intent action, and flags) that was used to start the scan.

  • If the PendingIntent does not match, the scan will continue running.

  • Calling this method when no background scan is active is safe and has no effect.

Resource Cleanup

Failing to stop background scans can lead to:

  • Excessive battery drain

  • Unnecessary BroadcastReceiver invocations

  • Potential throttling by the system on Android 8.0+

Parameters

pendingIntent

The same android.app.PendingIntent that was passed to startBackgroundScan. This identifies which scan session to stop.

See also