Skip to content

Commit

Permalink
[Fix] Android: SCAN_FAILED_ALREADY_STARTED could sometimes occur
Browse files Browse the repository at this point in the history
  • Loading branch information
chipweinberger committed Nov 8, 2024
1 parent 3b35a53 commit ab34577
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1915,14 +1915,14 @@ public void onReceive(Context context, Intent intent)

log(LogLevel.DEBUG, "OnAdapterStateChanged: " + adapterStateString(adapterState));

// stop scanning when adapter is turned off.
// stop scanning when adapter is turned back on.
// Otherwise, scanning automatically resumes when the adapter is
// turned back on. I don't think most users expect that.
if (adapterState != BluetoothAdapter.STATE_ON) {
if (adapterState == BluetoothAdapter.STATE_ON) {
if (mBluetoothAdapter != null && mIsScanning) {
BluetoothLeScanner scanner = mBluetoothAdapter.getBluetoothLeScanner();
if (scanner != null) {
log(LogLevel.DEBUG, "calling stopScan (Bluetooth Off)");
log(LogLevel.DEBUG, "calling stopScan (Bluetooth Restarted)");
scanner.stopScan(getScanCallback());
mIsScanning = false;
}
Expand Down

0 comments on commit ab34577

Please sign in to comment.