feat: improve scanning stability & connect to freshly bonded devs

This commit is contained in:
Stefan Zollinger
2024-08-19 14:39:23 +02:00
parent 48c6b2c314
commit d210a2754d
2 changed files with 11 additions and 6 deletions

View File

@@ -18,6 +18,7 @@ import android.bluetooth.le.ScanCallback
import android.bluetooth.le.ScanFilter
import android.bluetooth.le.ScanResult
import android.bluetooth.le.ScanSettings
import android.bluetooth.le.ScanSettings.MATCH_NUM_ONE_ADVERTISEMENT
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
@@ -210,6 +211,7 @@ class ConnectionManager(val context: Context, bleAdapter: BluetoothAdapter) {
private val scanSettings = ScanSettings.Builder()
.setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY)
.setNumOfMatches(ScanSettings.MATCH_NUM_ONE_ADVERTISEMENT)
.build()
private val bleScanner by lazy {
@@ -308,7 +310,8 @@ class ConnectionManager(val context: Context, bleAdapter: BluetoothAdapter) {
fun startScan() {
if (!isScanning) {
isScanning = true
bleScanner.startScan( null, scanSettings, scanCallback)
val filter = ScanFilter.Builder().setDeviceName("KIRBY").build()
bleScanner.startScan(listOf(filter), scanSettings, scanCallback)
}
}