我有一个简单的android应用,需要通过BLE连接到我们的硬件。
在iOS中,两种情况几乎都在同一时间。
情况1:
情况2:
使用的库:Android-Scanner-Compat-Library
代码:
扫描:
scanner = BluetoothLeScannerCompat.getScanner();
final ScanSettings settings = new ScanSettings.Builder()
.setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY)
.setUseHardwareBatchingIfSupported(false).build();
final List<ScanFilter> filters = new ArrayList<>();
Log.i(TAG, "Scanning.....");
scanner.startScan(filters, settings, scanCallback);
mHandler.postDelayed(() -> {
stopScan();
}, SCAN_DURATION);
停止扫描:
scanner.stopScan(scanCallback);