BLE Bluetoothの開発は、この記事ではあまりはっきり見えるかもしれません
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);
}
-
コンパイラヒント~~ startLeScan()~~廃止APIので、そうコードは以下のように書かれています
-
そして、各スキャン見つけ、自分のデバイスへのスキャンがいつも遅いです。
第二に、GitHubの上で突然の思考がありFastBle
、オープンソースのプロジェクトは、特別に設置デモ試しスキャンはすぐには表示されません。結果は、各時間はすぐに私は非常に困惑になり、デバイスをスキャンすることであり、彼はソースコードを直接見て、彼はAPIをスキャンしていることがわかったでしょうstartLeScan()
。
- つまり、スキャンコードは使用しない
BluetoothLeScanner
APIを
bluetoothAdapter.startLeScan(leScanCallback);