Skip to content

Instantly share code, notes, and snippets.

@tdcolvin
Last active January 4, 2024 23:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tdcolvin/12ff1be62a7d1394e548f47db1b9b650 to your computer and use it in GitHub Desktop.
Save tdcolvin/12ff1be62a7d1394e548f47db1b9b650 to your computer and use it in GitHub Desktop.
private var selectedDevice: BluetoothDevice? = null
private val scanCallback = object : ScanCallback() {
override fun onScanResult(callbackType: Int, result: ScanResult?) {
super.onScanResult(callbackType, result)
//TODO: Set the criteria for selecting the device. Here we check the device's
// name from the advertisement packet, but you could for example check its
// manufacturer, address, services, etc.
if (result.name == "MyDevice") {
//We have found what we're looking for. Save it for later.
selectedDevice = result.device
}
}
override fun onScanFailed(errorCode: Int) {
super.onScanFailed(errorCode)
//TODO: Something went wrong
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment