2017-06-03 156 views
0

我對Android開發非常陌生,目前我正在嘗試製作一個應用程序,可以從藍牙LE設備接收消息。它發送的信息非常重要,每次我掃描時我都會進行大量計算。我的問題是我應該把這個掃描方法放在一個單獨的線程上嗎?此外,在開始時,應用程序往往會快速掃描,然後掃描變得非常緩慢,我不知道爲什麼,想法?藍牙LE掃描儀線程

+0

你收到我的答案嗎?或者你需要別的東西? –

+0

對於BLE掃描,希望這個https://github.com/RustFisher/BluetoothScanner可以提供幫助。 –

回答

1

您不必從單獨的線程開始掃描,低能量掃描程序基於回調並且已經在單獨的線程中運行。

請把藍牙適配器上BluetoothLeScanner一看,startLeScan方法:

BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); 
BluetoothAdapter bluetoothAdapter = bluetoothManager.getAdapter(); 

bluetoothAdapter.getBluetoothLeScanner().startScan(yourCallback); // API 21+ 
bluetoothAdapter.startLeScan(yourCallback); // API 18+