BLE Bluetooth development may look less clear in this article
A first look at the code scan for Bluetooth
BluetoothManager bluetoothManager = (BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE);
BluetoothAdapter bluetoothAdapter = bluetoothManager.getAdapter();
//扫描蓝牙
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
BluetoothLeScanner scanner = bluetoothAdapter.getBluetoothLeScanner();
if (scanner != null) {
scanner.startScan(scanCallback);
}
} else {
bluetoothAdapter.startLeScan(leScanCallback);
}
-
Since the compiler hints ~~ startLeScan () ~~ obsolete API, so the code is written as
-
Then found each scan, scan to their own devices is always so slow.
Second, there is a sudden thought on GitHub FastBle
open source project, specially installed Demo Try scanning will not soon see. The result is that each time to quickly scan a device that makes me very puzzled; he would look directly at the source code, and found that he is scanning API startLeScan()
.
- That is, the scan code does not use
BluetoothLeScanner
API
bluetoothAdapter.startLeScan(leScanCallback);