Fix NullPointerException on startScan()
@@ -167,13 +167,17 @@ class ScanHelper {
} else if (!bluetoothAdapter.isEnabled()) {
LogManager.w(TAG, "Failed to start background scan on Android O: BluetoothAdapter is not enabled");
} else {
- int result = bluetoothAdapter.getBluetoothLeScanner().startScan(filters, settings, getScanCallbackIntent());
+ BluetoothLeScanner scanner = bluetoothAdapter.getBluetoothLeScanner();
+ if (scanner != null) {
+ int result = scanner.startScan(filters, settings, getScanCallbackIntent());
if (result != 0) {
LogManager.e(TAG, "Failed to start background scan on Android O. Code: " + result);
- }
- else {
+ } else {
LogManager.d(TAG, "Started passive beacon scan");
}
+ } else {
+ LogManager.e(TAG, "Failed to start background scan on Android O: scanner is null");
+ }
}
}
catch (SecurityException e) {
