Remember once BLE (Bluetooth Low Energy) scanning device around a slow pit

Here Insert Picture Description

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
    Here Insert Picture Description

  • Then found each scan, scan to their own devices is always so slow.

Second, there is a sudden thought on GitHub FastBleopen 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 BluetoothLeScannerAPI
bluetoothAdapter.startLeScan(leScanCallback);

Such a pleasant change to change it solved, I have to say really pit dead attractiveness ah! The new API API scanning speeds even slower than negligence, alas! Less then a sucking hair ...

Published 140 original articles · won praise 546 · views 540 000 +

Guess you like

Origin blog.csdn.net/a_zhon/article/details/100018719