Skip to content

Retrieve connected peripherals #469

Answered by twyatt
matheusdonatoni asked this question in Q&A
Discussion options

You must be logged in to vote

There currently isn't such a feature in Kable. It is generally assumed that the consumer will keep track (references) to peripherals.

For example, you might hold a list of peripherals:

val peripherals = mutableListOf<Peripheral>()

Finding the connected ones could be done with something like:

val connectedPeipherals = peripherals.filter { it.state.value == Connected }

Alternatively, you could keep a reference to peripherals in a Map (with the key being the MAC address):

val peripherals = mutableMapOf<String, Peripheral>()

Then you could use BluetoothManager.getConnectedDevices to cross reference with your list:

val addresses = BluetoothManager.getConnectedDevices(..).map { it.address }
val

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@matheusdonatoni
Comment options

Answer selected by matheusdonatoni
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants