Commit 9c5fc5e9 authored by Andreas Schildbach's avatar Andreas Schildbach
Browse files

ScannerFragment: Always show paired card10s, no matter if it's caught in the scan.

That way, we can unpair even if the card10 isn't available any more.
parent 3fd6494c
......@@ -48,18 +48,21 @@ class ScannerFragment : Fragment() {
val callback = object : ScanCallback() {
override fun onScanResult(callbackType: Int, result: ScanResult) {
val device = result.device
if (device.address.startsWith(CARD10_BLUETOOTH_MAC_PREFIX, true)) {
listAdapter.put(
Device(
btMac = device.address,
name = device.name,
paired = device.bondState == BluetoothDevice.BOND_BONDED
)
)
}
if (device.address.startsWith(CARD10_BLUETOOTH_MAC_PREFIX, true))
putToListAdapter(device)
}
}
private fun putToListAdapter(device: BluetoothDevice) {
listAdapter.put(
Device(
btMac = device.address,
name = device.name,
paired = device.bondState == BluetoothDevice.BOND_BONDED
)
)
}
val receiver = object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
System.out.println("===== onReceive " + intent)
......@@ -71,6 +74,14 @@ class ScannerFragment : Fragment() {
super.onCreate(savedInstanceState)
activity?.registerReceiver(receiver, IntentFilter(BluetoothDevice.ACTION_BOND_STATE_CHANGED))
bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
for (device in bluetoothAdapter.bondedDevices.filter {
it.address.startsWith(
CARD10_BLUETOOTH_MAC_PREFIX,
true
)
}) {
putToListAdapter(device)
}
bluetoothAdapter.bluetoothLeScanner.startScan(callback)
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment