I cannot get BLE devices.
For scan devices, I use no.nordicsemi.android.kotlin.ble:scanner:1.0.6
I call startBleScanning in the ViewModel.
Code:
val btDevicesLiveData = MutableLiveData<List<String>>()
private val aggregator = BleScanResultAggregator()
fun startBleScanning(context: Context) {
BleScanner(context).scan()
.map { aggregator.aggregateDevices(it) }
.onEach {
btDevicesLiveData.postValue(it.map { device ->
Log.d("BT", "result: ${device.address}")
})
}
.launchIn(viewModelScope)
}
In log, I see paired devices only.
Bluetooth on my phone is enabled. The device is enabled too.
How can I get BLE devices?
You can add custom settings when you execute the scan function:
A
BleScannerSettingsinstance has this structure:scanModeSet scan mode ([BleScanMode]) for Bluetooth LE scan.reportDelaySet report delay timestamp for Bluetooth LE scan.includeStoredBondedDevicesFlag indicating weather to include stored bonded devices in scan result.callbackTypeSet callback type ([BleScannerCallbackType]) for Bluetooth LE scan.numOfMatchesSet the number of matches ([BleNumOfMatches]) for Bluetooth LE scan filters hardware match.matchModeSet match mode ([BleScannerMatchMode]) for Bluetooth LE scan filters hardware match.legacySet whether only legacy advertisements should be returned in scan results.phySet the Physical Layer ([BleScannerPhy]) to use during this scan.Probably you are using legacy devices or you need to check the scan mode by default is
BleScanMode.SCAN_MODE_LOW_POWER