weliem / blessed-android

BLESSED, a Bluetooth Low Energy (BLE) library for Android
MIT License
557 stars 119 forks source link

How do I get the list of peripherals? #88

Closed sylque closed 3 years ago

sylque commented 3 years ago

I want to populate a list of peripherals, so that the user can select the one he wants to connect to.

Unfortunately, it seems the scanForPeripheralsXXX()+callback mechanism allows either:

What am I missing?

weliem commented 3 years ago

ScanForPeripherals() will scan continuously and only stops when you call stopScanning()

So simply dont stop the scan...

sylque commented 3 years ago

Thanks for your answer. If I don't stop the scan, I get an unlimited number of duplicates:

I/PERIPHERAL: noname 1C:98:EC:78:A0:54
I/PERIPHERAL: noname 1C:98:EC:78:A0:54
I/PERIPHERAL: noname 1C:98:EC:78:A0:54
I/PERIPHERAL: noname 1C:98:EC:78:A0:54
I/PERIPHERAL: noname 1C:98:EC:78:A0:54
I/PERIPHERAL: noname 1C:98:EC:78:A0:54
I/PERIPHERAL: noname 1C:98:EC:78:A0:54
I/PERIPHERAL: noname 1C:98:EC:78:A0:54
I/PERIPHERAL: noname 1C:98:EC:78:A0:54
I/PERIPHERAL: noname 1C:98:EC:78:A0:54
I/PERIPHERAL: noname 1C:98:EC:78:A0:54
I/PERIPHERAL: noname 1C:98:EC:78:A0:54
I/PERIPHERAL: noname 1C:98:EC:78:A0:54
I/PERIPHERAL: noname 1C:98:EC:78:A0:54
I/PERIPHERAL: noname 1C:98:EC:78:A0:54
I/PERIPHERAL: LaserPa E7:A9:04:1C:A9:54
I/PERIPHERAL: noname 1C:98:EC:78:A0:54
I/PERIPHERAL: noname 1C:98:EC:78:A0:54
I/PERIPHERAL: noname 1C:98:EC:78:A0:54
I/PERIPHERAL: noname 1C:98:EC:78:A0:54
I/PERIPHERAL: noname 1C:98:EC:78:A0:54
I/PERIPHERAL: noname 1C:98:EC:78:A0:54
I/PERIPHERAL: noname 1C:98:EC:78:A0:54
I/PERIPHERAL: noname 1C:98:EC:78:A0:54
I/PERIPHERAL: noname 1C:98:EC:78:A0:54
I/PERIPHERAL: noname 1C:98:EC:78:A0:54
I/PERIPHERAL: noname 1C:98:EC:78:A0:54
I/PERIPHERAL: noname 1C:98:EC:78:A0:54
I/PERIPHERAL: noname 1C:98:EC:78:A0:54
I/PERIPHERAL: noname 1C:98:EC:78:A0:54
I/PERIPHERAL: noname 1C:98:EC:78:A0:54
I/PERIPHERAL: noname 1C:98:EC:78:A0:54
I/PERIPHERAL: noname 1C:98:EC:78:A0:54
I/PERIPHERAL: LaserPa E7:A9:04:1C:A9:54
I/PERIPHERAL: noname 1C:98:EC:78:A0:54
I/PERIPHERAL: noname 1C:98:EC:78:A0:54
I/PERIPHERAL: noname 1C:98:EC:78:A0:54
I/PERIPHERAL: noname 1C:98:EC:78:A0:54
I/PERIPHERAL: noname 1C:98:EC:78:A0:54
I/PERIPHERAL: noname 1C:98:EC:78:A0:54
I/PERIPHERAL: noname 1C:98:EC:78:A0:54
...

Of course I could wait a bit before stopping the scan, then remove the duplicates manually. That sounds cumbersome, though. Isn't there any other way?

sylque commented 3 years ago

After reading a bit about it, it seems continuous scanning is the way the underlying Android BLE layer works. Sorry for the dumb question.