Handling Bluetooth off during scanning

This commit is contained in:
Aleksander Nowakowski 2018-10-24 13:56:12 +02:00
parent 54c1b227a4
commit d68e771a78
2 changed files with 6 additions and 0 deletions

View File

@ -73,6 +73,8 @@ public class BootloaderScannerJB implements BootloaderScanner, BluetoothAdapter.
}, "Scanner timer").start();
final BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
if (adapter == null || adapter.getState() != BluetoothAdapter.STATE_ON)
return null;
adapter.startLeScan(this);
try {

View File

@ -78,7 +78,11 @@ public class BootloaderScannerLollipop extends ScanCallback implements Bootloade
}, "Scanner timer").start();
final BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
if (adapter == null || adapter.getState() != BluetoothAdapter.STATE_ON)
return null;
final BluetoothLeScanner scanner = adapter.getBluetoothLeScanner();
if (scanner == null)
return null;
/*
* Scanning with filters does not work on Nexus 9 (Android 5.1). No devices are found and scanner terminates on timeout.
* We will match the device address in the callback method instead. It's not like it should be, but at least it works.