Skip to content

Commit

Permalink
fix: Correct an Android bug where stopping a scan when there's no lon…
Browse files Browse the repository at this point in the history
…ger a Bluetooth adapter/scanner can cause an NPE
  • Loading branch information
blackspherefollower committed Oct 2, 2024
1 parent 0eb6188 commit 1b7e369
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,13 @@ public void startScan(ScanFilter filter) {

@SuppressLint("MissingPermission")
public void stopScan() {
BluetoothAdapter.getAdapter().getBluetoothLeScanner().stopScan(this.callback);
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (bluetoothAdapter != null) {
BluetoothLeScanner scanner = bluetoothAdapter.getBluetoothLeScanner();
if (scanner != null) {
scanner.stopScan(this.callback);
}
}
}

private native void reportScanResult(ScanResult result);
Expand Down

0 comments on commit 1b7e369

Please sign in to comment.