Improve Apple, Android and Windows (#40)

* Cleanup connection

* Reverse search list

* Bump version

* Fix Android serviceUuids in scanResults

* Fix typo

* Improve cleanup on apple

* Improve Apple reconnection and service discovery

* Persist long scan result name on Windows

Co-authored-by: navidecklabs <navidecklabs@users.noreply.github.com>

* Update changelog

---------

Co-authored-by: Rohit Sangwan <rohitsangwan647@gmail.com>
Co-authored-by: navidecklabs <navidecklabs@users.noreply.github.com>
This commit is contained in:
Foti Dim
2024-05-09 11:48:32 +02:00
committed by GitHub
parent 3be945c3d5
commit fef4e8526b
10 changed files with 88 additions and 26 deletions
@@ -238,7 +238,7 @@ fun BluetoothDevice.removeBond() {
try {
javaClass.getMethod("removeBond").invoke(this)
} catch (e: Exception) {
Log.e(TAG, "Removing bond has been failed. ${e.message}")
Log.e(TAG, "Removing bond failed. ${e.message}")
}
}
@@ -665,6 +665,15 @@ class UniversalBlePlugin : UniversalBlePlatformChannel, BluetoothGattCallback(),
override fun onScanResult(callbackType: Int, result: ScanResult) {
// Log.v(TAG, "onScanResult: $result")
var serviceUuids: Array<String> = arrayOf<String>()
result.device.uuids?.forEach {
serviceUuids += it.uuid.toString()
}
result.scanRecord?.serviceUuids?.forEach {
if (!serviceUuids.contains(it.uuid.toString())) {
serviceUuids += it.uuid.toString()
}
}
mainThreadHandler?.post {
callbackChannel?.onScanResult(
UniversalBleScanResult(
@@ -673,13 +682,12 @@ class UniversalBlePlugin : UniversalBlePlatformChannel, BluetoothGattCallback(),
isPaired = result.device.bondState == BOND_BONDED,
manufacturerDataHead = result.manufacturerDataHead,
rssi = result.rssi.toLong(),
services = result.device.uuids?.map { it.uuid?.toString() ?: "" }
?: emptyList()
services = serviceUuids.toList()
)
) {}
}
}
override fun onBatchScanResults(results: MutableList<ScanResult>?) {
Log.v(TAG, "onBatchScanResults: $results")
}